I don’t have much experience with triggers, so I’m having an issue where I need to use a function from another script when I trigger the trigger object, I’ve refenced the script to use the function but i can’t figure out how to get the function to activate in the OnTriggerEnter function. I use to have it using colliders with OnCollisionEnter and it worked but i wanted it to be a trigger instead and now it doesn’t work.
any help to get this function to work would be much appreciated
public class SpeedBoost : MonoBehaviour
{
public GameObject speedBoost; // reference to the trigger object
public int speedBoostmultiplier = 5; // interger to add to the value maxspeed in other script
void Update() // not relevant to the problem
{
float z = Mathf.PingPong(Time.time, 1f);
Vector3 axis = new Vector3(1, 1, z);
transform.Rotate(axis, 1f);
}
void OnTriggerEnter()
{
speedBoost.SetActive(false); //just sets the trigger object to not active
//this is the issue down below vvv
PrometeoCarController Carspeed = GetComponent<PrometeoCarController>(); // referencess the other script to access the function
if (Carspeed != null)
{
Carspeed.SpeedIncrease(speedBoostmultiplier); //activate the function in the other script
}
}
}
and this is the function from the other script that is referenced:
[code=CSharp]public void SpeedIncrease(int increase) // the fuction i need to use
{
maxSpeed += increase; // adds the maxspeed value by the increase int(speedBoostmultiplier)
}