- Home /
How to switch between scripts on trigger?
I'm pretty new to C# so sorry if this is an easy script to figure out.
So I have a box collider on a cube, that when I shoot it with a projectile I want it to activate a power-up, which is another script. The original script is a click-and-shoot script, and the power-up script allows the player to click-and-hold to rapid fire. I know it has something to do with tags to trigger the script switch when a projectile hits it. I also wanted the power-up script to only last for a set amount of time before reverting back to the click-and-shoot script.
Any help would be much appreciated. :)
Answer by piter00999 · Nov 26, 2018 at 05:45 PM
I have couple of ideas how to make it:
Add your power-up script to player object at runtime: After detecting that cube was hit add to player object new component like this:
player.AddComponent<MyPowerUpScript>();
Active your power-up script which was preadded to player object in editor, after detecting that cube was hit grab reference to powerup script and do something like that
mypowerUp.SetActive(true)
Your answer
![](https://koobas.hobune.stream/wayback/20220612182811im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to change between scripts on trigger? 2 Answers
Does anyone know how to activate different scripts OnTrigger? 1 Answer
Outline Shader not working correctly on blender models 0 Answers
Script on multiple objects not working properly! 1 Answer
CharacterController.isGrounded not working,CharacterController.isGrounded Not Working 4 Answers