private void OnTriggerEnter(Collider other) { BoxPickable box = other.GetComponent <BoxPickable>(); // the object is a box and it gets delivered if (box != null) { box.Delivery(); } }
public void GenerateBox() { // cannot hold more than one box if (transform.GetComponentsInChildren <BoxPickable>().Length > 0) { return; } // instantiate a new box BoxPickable box = Instantiate(boxPrefab, transform.position, Quaternion.identity, transform); // add callbacks to the box events box.OnPickUp += DelayGenerateBox; }
public void RespawnAtSpawnPoint(Transform target, int index) { SpawnPoint spawnPoint = spawnPoints[index]; // if the spawn point is already occupied use the first free one if (spawnPoint.Occupied) { spawnPoint = GetFirstFreeSpawnPoint(); } spawnPoint.Occupied = true; // set target position and rotation as the spawn point chosen target.SetPositionAndRotation(spawnPoint.transform.position, spawnPoint.transform.rotation); // if the target is holding a box it get despawned BoxPickable box = target.GetComponentInChildren <BoxPickable>(); if (box != null) { box.Despawn(); } }