Question by
luckydeva · Apr 05, 2017 at 07:32 AM ·
c#scripting beginnerarray of gameobjectsrotating
How i apply rotating animation via script ?
I spawn my object using array at not trouble at all, but when it came to animate rotation using transform.rotate i confuse because my object dont rotating. i include my script so you guys can help me.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class spawn : MonoBehaviour {
//public string[] objek;
int buatrandom;
int jumlahrandom = 16 ;
int objek1 ;
int objek2 ;
int objek3 ;
public string objname1;
public string objname2;
public string objname3;
private GameObject target1;
private GameObject target2;
private GameObject target3;
public int [] simpannomorobject ;
public GameObject[] nomorasset;
public float speed =10f;
// Use this for initialization
void Start () {
simpannomorobject = new int[3];
for (int i = 0; i < 2; i++) {
buatrandom = Random.Range (0, jumlahrandom);
simpannomorobject [i] = buatrandom;
if (i > 0){
if (i < 3) {
buatobjek ();
}
}
}
}
void buatobjek (){
objek1 = simpannomorobject [0];
objek2 = simpannomorobject [1];
objek3 = simpannomorobject [2];
Instantiate (nomorasset [objek1], new Vector3 (0, 0, 3.0f), Quaternion.identity);
Instantiate (nomorasset [objek2], new Vector3 (4.0f, 0, 0), Quaternion.Euler(0,90,0));
Instantiate (nomorasset [objek3], new Vector3 (-4.0f, 0, 0), Quaternion.Euler(0,-90,0));
objname1 = nomorasset [objek1].name;
objname2 = nomorasset [objek2].name;
objname3 = nomorasset [objek3].name;
}
// Update is called once per frame
void Update () {
target1 = nomorasset [objek1];
target1.transform.Rotate(100 * Time.deltaTime, 0 , 0);
}
}
Comment