My goal through this code in C # is withthat each support of a key totime the player presses the Q I create a cube, to at a fixed position given by another object, but takingthen begin translating it in a random direction translation
support 1> translation 1
support2> translation 2
support 3> translation 3
etc..... ie.
- first press: a cube is created at the spawn point and moves away in direction 1
- second press: a cube is created at the spawn point and moves away in direction 2
- third press: a cube is created at the spawn point and moves away in direction 3
Here is myI don't understand why the code, but it below does not work.:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class spawn_random_trajet : MonoBehaviour {
public GameObject Spawn, Spawn2;
public Transform origineSpawn;
public float moveSpeed=5f;
// Use this for initialization
void StartUpdate () {
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.Q)) {
int random_trajet_x = Random.Range (-10,10);
int random_trajet_y = Random.Range (-10,10);
int random_trajet_z = Random.Range (-10,10);
Spawn2 =Instantiate= Instantiate(
Spawn,
origineSpawn.position,
origineSpawn.rotation
) as GameObject;
transform.Translate (
random_trajet_x*Time.deltaTime*moveSpeed,
random_trajet_y*Time.deltaTime*moveSpeed,
random_trajet_z*Time.deltaTime*moveSpeed
);
}
}
}