I’m trying to script a cube where upon going through a bigger cube, it increases speed.
Here’s my code:
using UnityEngine;
using System.Collections;
public class IncreaseSpeed : MonoBehaviour {
public float speed;
void OnTriggerEnter(Collider other) {
if(other.gameObject.CompareTag("Trigger01")){
rigidbody.AddForce(0,0,speed);
Debug.Log("We've finally touched!");
}
}
}
The console reads the Debug Log “We’ve finally touched!” so it’s detecting collision and the trigger does work.
So why isn’t a force being added to the cube? I was thinking maybe it’s because I have this in an OnTriggerEnter method and that it’s only adding a force to the rigidbody for one frame?
I’d appreciate any assistance. Thank you for your time.