- Home /
speed diffrence
This code is connected to for game-objects but for some reason all of the game-objects get different speeds and they all started with the same speed.(the tags are set correctly)
using UnityEngine; using System.Collections;
public class Arrow : MonoBehaviour {
public GameObject target;
public GameObject target1;
public GameObject target2;
public GameObject target3;
public GameObject target4;
public GameObject target5;
public GameObject target6;
public GameObject target7;
private int speed = 5;
private int ranN;
void Update () {
transform.position += Vector3.back * speed * Time.deltaTime;
}
void OnTriggerEnter (Collider other) {
if (other.gameObject.CompareTag ("reset")) {
ranN = Random.Range (1, 8);
}
if (ranN == 1) {
transform.position = target.transform.position;
speed = speed + 1;
} else {
if (ranN == 2) {
transform.position = target1.transform.position;
speed = speed + 1;
} else {
if (ranN == 3) {
transform.position = target2.transform.position;
speed = speed + 1;
} else {
if (ranN == 4) {
transform.position = target3.transform.position;
speed = speed + 1;
} else {
if (ranN == 5) {
transform.position = target4.transform.position;
speed = speed + 1;
} else {
if (ranN == 6) {
transform.position = target5.transform.position;
speed = speed + 1;
} else {
if (ranN == 7) {
transform.position = target6.transform.position;
speed = speed + 1;
}
}
}
}
}
}
}
}
}
I see a narrative but no question. UnityAnswers implies a question to be asked first.
As u are increasing speed on onTriggerEnter the more a object hit it gets more speed. And speed is private variable so all will start with same speed value of 5 and changing speed when hitting some other collider individually. In this code u r not assigning velocity, U r changing its position. Assign Velocity to rigidbody to move object if u only purpose is to move
You are giving all with same speed thats why they are starting with same speed.but what is the final question in that.can u give more info about then anyone can give you good solution.