Hi!
I have created this script, and it works perfectly. Now I want to insert a countdown of 10 seconds, and when it ends the “other” object should return in his inizial scale. Can you help me?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PowerUpBigEffect : MonoBehaviour {
void OnTriggerEnter2D(Collider2D other) {
if (other.gameObject.name == "player") {
other.transform.localScale -= new Vector3 (0.1f, 0.1f, 0f);
Destroy (this.gameObject);
}
}
}
You could use a coroutine to handle that, or Invoke.
Make sure that you either don’t destroy the power up game object before they’re done running, though. You could hide them, for instance and make sure they can’t be picked up, again. They wouldn’t complete on a destroyed game object.
Or you could run the coroutine/invoke on the player game object, instead.