Mon but à travers ce code en C # est,à chaque appui de la touche Q(par exemple),de créer,instantier un cube à une position fixe donnée par un autre objet, mais en prenant une translation de direction aléatoire
appui 1> création du cube à position fixe origineSpawn et translation de vecteur 1 à coordonnées aléatoires
appui 2> création du cube à position fixe origineSpawn et translation de vecteur 2 à coordonnées aléatoires
appui 3> création du cube à position fixe origineSpawn et translation de vecteur 3 à coordonnées aléatoires
etc......
voici mon code correct qui se compile:
Code : Tout sélectionner
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 Start () {
}
// 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 (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);
}
}
}
Pourquoi?
merci de votre aide