I would like to create an object dynamically when the player presses Q and use this object in Instantiate
and in transform.Translate
.
The problem is that the translation must be outside the if
that checks for the Q press, but it applies to the cube that I created inside the if
.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class instancier_new_object : MonoBehaviour {
public float moveSpeed=5f;
void Update () {
if (Input.GetKeyDown (KeyCode.Q)) {
GameObject objet = new GameObject ("objet");
GameObject cube = new GameObject ("cube");
cube = Instantiate(
objet,
new Vector3(1, 2, 3),
Quaternion.identity
);
}
cube.transform.Translate(
Time.deltaTime*moveSpeed,
0,
-Time.deltaTime*moveSpeed,
Space.Self
);
}
}
No comments:
Post a Comment