Trick is now pickup-able and is not scored by baskets
This commit is contained in:
@@ -15,7 +15,7 @@ GameObject:
|
||||
- component: {fileID: 700000005}
|
||||
m_Layer: 0
|
||||
m_Name: Trick
|
||||
m_TagString: Untagged
|
||||
m_TagString: Interactable
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
|
||||
@@ -2621,8 +2621,9 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::Spawner
|
||||
objectToSpawn: {fileID: 700000000, guid: 8bf8957665594a718535d06aba0cdee7, type: 3}
|
||||
spawnInterval: 6
|
||||
spawnInterval: 3
|
||||
maxAlive: 1
|
||||
spawnOnStart: 1
|
||||
--- !u!1660057539 &9223372036854775807
|
||||
SceneRoots:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -10,6 +10,11 @@ public class BasketController : MonoBehaviour
|
||||
|
||||
if (collision.gameObject.CompareTag("Interactable"))
|
||||
{
|
||||
if (collision.gameObject.GetComponent<TrickController>() != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
scoreManager.AddPoints(1);
|
||||
|
||||
GameObject.Destroy(collision.gameObject);
|
||||
|
||||
@@ -92,6 +92,11 @@ public class PlayerPickupController : MonoBehaviour
|
||||
rb.mass = 0;
|
||||
}
|
||||
|
||||
if (heldObject.TryGetComponent<TrickController>(out var trick))
|
||||
{
|
||||
trick.SetCarried(true);
|
||||
}
|
||||
|
||||
if (col != null) col.enabled = false;
|
||||
break;
|
||||
}
|
||||
@@ -106,6 +111,10 @@ public class PlayerPickupController : MonoBehaviour
|
||||
rb.bodyType = RigidbodyType2D.Dynamic;
|
||||
rb.gravityScale = 1;
|
||||
}
|
||||
if (heldObject.TryGetComponent<TrickController>(out var trick))
|
||||
{
|
||||
trick.SetCarried(false);
|
||||
}
|
||||
Collider2D col = heldObject.GetComponent<Collider2D>();
|
||||
if (col != null) col.enabled = true;
|
||||
|
||||
|
||||
@@ -9,9 +9,18 @@ public class Spawner : MonoBehaviour
|
||||
// Time interval between spawns
|
||||
public float spawnInterval = 1f;
|
||||
[SerializeField] private int maxAlive = 0;
|
||||
[SerializeField] private bool spawnOnStart = true;
|
||||
|
||||
private readonly List<GameObject> spawned = new List<GameObject>();
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (spawnOnStart)
|
||||
{
|
||||
SpawnOnce();
|
||||
}
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Start the spawning process using a Coroutine
|
||||
@@ -35,11 +44,25 @@ public class Spawner : MonoBehaviour
|
||||
continue;
|
||||
}
|
||||
|
||||
// Spawn the object at the spawner's position and rotation
|
||||
SpawnOnce();
|
||||
}
|
||||
}
|
||||
|
||||
private void SpawnOnce()
|
||||
{
|
||||
if (objectToSpawn == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (maxAlive > 0 && CountAlive() >= maxAlive)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var instance = Instantiate(objectToSpawn, transform.position, Quaternion.identity);
|
||||
spawned.Add(instance);
|
||||
}
|
||||
}
|
||||
|
||||
private int CountAlive()
|
||||
{
|
||||
|
||||
@@ -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