Je voudrais faire un script qui dit que je peux detruire un gameobject uniquement pendant une duée precise en appuyant sur une touche comme"a".
J'ai créé le script mais ca ne marche pas :
Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class zombieun : MonoBehaviour {
public GameObject target;
public float timer = 7f;
public float realtime = 0f;
void Start () {
target.SetActive (false);
Invoke ("activatetarget", 5);
}
void activatetarget () {
target.SetActive (true);
}
void Update () {
target.transform.Translate (-Time.deltaTime, 0, 0);
timer = realtime + Time.timeSinceLevelLoad;
if ( Input.GetKey("a") && timer == realtime)
{
Destroy(target);
}
}
}