My level

Hi guys… I want to make the 2nd rocket (circled) trigger when the player flies over it, and fly quickly straight upwards, as a missle. Any tips on how to do this?

1 Like

Hi Andy,

First of all, great scene. I love this low-poly design. :slight_smile:

Regarding your problem, you could add a trigger collider (a large BoxCollider) in the area. If the rocket touches it (e.g. OnTriggerEnter), you could launch the second rocket.


See also:

1 Like

Nina beat me to it. I would say a trigger as well, initially I was thinking a ray trace to sense when it happens too. But it is a bit more complex, when a simple trigger will do it.

Hi guys…I’m working on it, but I’m pretty new to scripting. As far as I can tell I need 2 scripts. One to trigger the missile, and one very basic movement script for the missile to fly straight upwards when triggered. Can anyone assist? THANK YOU!

1 Like

It depends on your concept. If you want to reuse the collider/concept for different types of objects, make a separate script, which could act as a detector. In this script, you could create a variable of type Launcher with the [SerializeField] attribute.

Then you create a Launcher script, which you attach to the second rocket. Drag the component into the exposed field of the Detector component.

Now you can program the behaviour. Create a public method in the Launcher class which you call in your Detector instance. This method could give the second rocket a velocity.

Before worrying about any details, try to make this work first.

1 Like

okay, I’m almost there, but one very technical question (by my standards, anyway!)

How do I make a script wait to be triggered by another script, instead of firing right away?

1 Like

C# scripts do not fire right away. Without a method call, nothing will happen. Unity methods like Awake and Start get called automatically by Unity when the instance gets created. Update gets called each frame. OnTrigger* and OnCollision* get called when a collision event happens.

Your own methods do not get executed unless you call them.

Add Debug.Logs to your methods. This way, you can see in your control when something is being executed in your code.

1 Like

This topic was automatically closed after 14 days. New replies are no longer allowed.

Privacy & Terms