Hello, I am having this problem with my laser (bolt) that I am firing but never get destroyed by the boundary, the OntriggerExit is not even called. The script used in the tutorial is different from mine, seems to be an old version… I need a little help on this please
Here is my code.
public class DestroyByBoundary : MonoBehaviour
{
void OntriggerExit(Collider other)
{
Debug.Log (other.name);
Destroy(other.gameObject);
}
}
public class Mover : MonoBehaviour
{
private Rigidbody laser;
public float speed;
void Start ()
{
laser = GetComponent<Rigidbody>();
laser.velocity = transform.forward * speed;
}
}
[System.Serializable]
public class Boundary
{
public float xMin, xMax, zMin, zMax;
}
public class PlayerControlller : MonoBehaviour
{
private Rigidbody player;
public float speed;
public float tilt;
public Boundary boundary;
public GameObject shot;
public Transform shotSpawn;
public float fireRate;
private float nextFire;
void Update()
{
if (Input.GetButton ("Fire1") && Time.time > nextFire)
{
nextFire = Time.time + fireRate;
Instantiate (shot, shotSpawn.position, shotSpawn.rotation);
}
}
void FixedUpdate()
{
player = GetComponent<Rigidbody>();
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
player.velocity = movement * speed;
player.position = new Vector3
(
Mathf.Clamp (player.position.x, boundary.xMin, boundary.xMax),
0.0f,
Mathf.Clamp (player.position.z, boundary.zMin, boundary.zMax)
);
player.rotation = Quaternion.Euler (0.0f, 0.0f, player.velocity.x * -tilt);
}
}
Thanks