using System;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityStandardAssets.Characters.ThirdPerson;
public class Multiple_objects : MonoBehaviour {
public GameObject prefab;
public GameObject[] gos;
public int NumberOfObjects;
private ThirdPersonCharacter[] thirdPersonCharacter;
private Animator[] _animator;
private int count = 0;
private List<float> floats = new List<float>();
public float smooth = 1f;
private Vector3 targetAngles;
void Awake()
{
Vector3 v3 = prefab.transform.position;
_animator = new Animator[NumberOfObjects];
gos = new GameObject[NumberOfObjects];
for(int i = 0; i < gos.Length; i++)
{
count = count + 2;
GameObject clone = (GameObject)Instantiate(prefab, Vector3.zero, Quaternion.identity);
gos [i] = clone;
gos [i].transform.position = new Vector3 (v3.x - count, v3.y, v3.z);
_animator [i] = gos[i].GetComponent<Animator> ();
float randomspeed = 0f;
// Keep repeating this until we find an unique randomspeed.
while(randomspeed == 0f || floats.Contains(randomspeed))
{
randomspeed = UnityEngine.Random.Range(1.0f, 15.0f);
}
floats.Add (randomspeed);
//float vertInput = 1.0f;
_animator [i].SetFloat ("Speed", randomspeed);
if (randomspeed != 0.0f)
_animator[i].speed = randomspeed;
else
_animator [i].speed = 1.0f;
}
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.S)) // some condition to rotate 180
targetAngles = gos[5].transform.eulerAngles + 180f * Vector3.up; // what the new angles should be
transform.eulerAngles = Vector3.Lerp(gos[5].transform.eulerAngles, targetAngles, smooth * Time.deltaTime); // lerp to new angles
}
}
In the Hierarchy i have two ThirdPersoncontroller: ThirdPersonController and ThirdPersonController(1)
I put the script on the ThirdPersonController and the prefab is the ThirdPersonController(1) then it's cloning more 15 ThirdPersonControllers.
Then each of the cloned 15 players walk in another speed. Now in the Update function when i press on the S key the ThirdPersonController is turning 180 degrees and then all the cloned 15 players also turn 180 degrees and keep walking to this direction.
What i want to do is when one of the cloned players getting to Z position turn 180 degrees only this player and turn on place 180 degrees for a second ot two walk on place turn then continue walking to the turned direction.
So in the Update function i'm using now the S key as condition but it's turning the ThirdPersonController and all the clones turn according to him and walk to the turned direction.
I tried to use gos[0].transform also gos[5].transform but it's not turning only the fifth clone but turn all of them 180 degrees.
And the condition i tried to make if(gos[0].transform.position.z == 108.9377f) or if(gos[0].transform.position.z == 100) but it's never get to the next line i used a break point.