iI would like to create an object dynamically when the player presses Q and use itsthis object in InstantiateInstantiate and in transform.Translate but i can't !
Blockquote using System.Collections;
using System.Collectionstransform.Translate.Generic;
using UnityEngine;
public class instancier_new_objectThe problem is that the translation must be outside the : MonoBehaviourif that checks for the {Q press, but it applies to the cube that I created inside the if.
public floatusing moveSpeed=5f;System.Collections;
using System.Collections.Generic;
using UnityEngine;
// Use thispublic forclass initialization
voidinstancier_new_object Start: ()MonoBehaviour {
}
//public Updatefloat ismoveSpeed=5f;
called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.Q)) {
GameObject objet = new GameObject ("objet");
GameObject cube = new GameObject ("cube");
cube=Instantiate cube = Instantiate(
objet,
new Vector3 (1, 2, 3),
Quaternion.identity);
}
);
}
// the problem is that the translation must be outside the if while only applies to the cube that can only be created in if
cube.transform.Translate(
Time.deltaTime*moveSpeed,
0,
-Time.deltaTime*moveSpeed,
Space.Self
);
}
}
}
Can you correct me?
thanks