How to trigger a object to change position/transform?

Hello readers,

I’m currently working on a 3D platformer a bit similar to RE:RUN (RE:RUN by Dani). In that game for example, when all the enemies all die in a certain area (or just a single enemy) an event is triggered to make a object appear. It’s also the same when the player presses a button. I’ve been looking through forum posts and also being searching YouTube too but I have not found a tutorial or a few examples on how to do it.

edit: I’ve joined recently, but I’ve just made a new account because I changed emails.

If anybody could help, it would mean a lot to me!

Kind regards,
coreyhsGames

I’m not sure I understand the question, I’m sorry- are you trying to spawn in the object? (Instantiate) Or are you trying to modify its position? (Transform)

Idk what your code looks like, but here’s how I spawn a missile when the shoot missile button is pressed:
GameObject missile1 = Instantiate(test, transform.position - missileOffset1, transform.rotation);

Or, you can change its position with Transform.position. but be careful, transform.position is the GLOBAL axis, and transform.localPosition is the LOCAL axis.

void Update()
{
float addAmount = Mathf.Sin(0.01f * swayCounter) * swayMagnitude * Time.deltaTime;
transform.localPosition += Vector3.up * addAmount;
swayCounter++;
}

Hope that helps!

1 Like