Trick is now pickup-able and is not scored by baskets
This commit is contained in:
@@ -16,6 +16,7 @@ public class TrickController : MonoBehaviour
|
||||
private float nextTargetTime;
|
||||
private Vector2 wanderDirection;
|
||||
private float nextWanderTime;
|
||||
private bool isCarried;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -29,9 +30,24 @@ public class TrickController : MonoBehaviour
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (isCarried)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Time.time >= nextTargetTime)
|
||||
{
|
||||
target = FindNearestTreat();
|
||||
if (target == null)
|
||||
{
|
||||
// If we can't find treats while we're tagged Interactable, keep moving.
|
||||
wanderDirection = Random.insideUnitCircle.normalized;
|
||||
if (wanderDirection.sqrMagnitude < 0.01f)
|
||||
{
|
||||
wanderDirection = Vector2.right;
|
||||
}
|
||||
nextWanderTime = Time.time + wanderInterval;
|
||||
}
|
||||
nextTargetTime = Time.time + targetRefreshInterval;
|
||||
}
|
||||
|
||||
@@ -50,6 +66,11 @@ public class TrickController : MonoBehaviour
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (isCarried)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Vector2 desiredVelocity;
|
||||
var stopForTreat = false;
|
||||
if (target != null)
|
||||
@@ -82,6 +103,10 @@ public class TrickController : MonoBehaviour
|
||||
for (var i = 0; i < treats.Length; i++)
|
||||
{
|
||||
var candidate = treats[i];
|
||||
if (candidate == gameObject)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!candidate.activeInHierarchy)
|
||||
{
|
||||
continue;
|
||||
@@ -105,11 +130,16 @@ public class TrickController : MonoBehaviour
|
||||
|
||||
private void TryConsumeTreat()
|
||||
{
|
||||
if (isCarried)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var hits = Physics2D.OverlapCircleAll(transform.position, consumeDistance);
|
||||
for (var i = 0; i < hits.Length; i++)
|
||||
{
|
||||
var hit = hits[i];
|
||||
if (hit == null || !hit.CompareTag(treatTag))
|
||||
if (hit == null || hit.gameObject == gameObject || !hit.CompareTag(treatTag))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -122,4 +152,16 @@ public class TrickController : MonoBehaviour
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetCarried(bool carried)
|
||||
{
|
||||
isCarried = carried;
|
||||
if (carried)
|
||||
{
|
||||
target = null;
|
||||
var velocity = body.linearVelocity;
|
||||
velocity.x = 0f;
|
||||
body.linearVelocity = velocity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user