- Home /
Does anyone know how to activate different scripts OnTrigger?
I'm still new to C#, so sorry if this is an easy script to figure out.
So, I have a box collider on a cube (which is a power-up), which when I shoot it with a projectile, I want another script to activate. (The original script is a click-and-shoot projectile script and the power-up script lets the player click and hold to rapid fire.) The click-and-shoot projectile script is always initially activated. I also need the power-up to only last for a set amount of time, then the click-and-shoot script is re-activated.
I know that tags are involved to trigger something only when a projectile hits the power-up, but I don't know the implementation process of that as well.
Any help would be much appreciated. :)
Answer by Marshal_Alessi · Nov 26, 2018 at 05:01 AM
Okay I think I'm following you. So the first step is that your projectile needs some sort of collider to detect collision. Unless the projectile needs to calculate physics and 'bump' into other objects, you can check the checkbox on the trigger Is Trigger. You'll want to identify the projectile, and an easy way to do that is to add a 'tag' to the prefab. Then, inside a C# placed on your powerup cube, you'd put:
public someScriptName script; //drag and drop the script you want to talk to in the editor
void OnTriggerEnter(Collider col)
{
if(col.gameObject.tag.Equals("Projectile"))
{
//Activate other script
someScriptName.somefunction();
}
}
Your answer
Follow this Question
Related Questions
How to change between scripts on trigger? 2 Answers
How to switch between scripts on trigger? 1 Answer
Repawning pickup, disable renderer and collider 1 Answer
Can I make a hole in a mesh collider? 2 Answers
Unity Collider Penetrating detection 0 Answers