- Home /
Change rotation way of instantiated object
Hello, I am newbie in Unity, sorry for this basic question but I can't find any source about my problem.
In my project, I have a ball and many instantiated circles which continuous rotating in z position. All the circles are instantiating from a prefab called "CircleWhite" which has one script and the script includes only;
public class rotation : MonoBehaviour {
public float rotationSpeed = 100f;
void Update () {
transform.Rotate(0f, 0f, (rotationSpeed * Time.deltaTime));
}
}
So, all the circles are rotating in the same position and speed. However, I want to reverse the direction of some circles and change the speed. I used these code for instantiated circles in my "ball script";
CircleWhite.transform.localScale = new Vector3(0.6f, 0.6f, 0.6f);
Instantiate(CircleWhite, new Vector3(-1f, yPosition, transform.position.z), transform.rotation);
Instantiate(CircleWhite, new Vector3(1f, yPosition, transform.position.z), transform.rotation);
For example, I am instantiating two circles above but I want to change direction of one of them. "-transform.rotation" does not work. What can I do about that?
Answer by ecv80 · Nov 19, 2018 at 04:16 PM
Instantiate(CircleWhite, new Vector3(1f, yPosition, transform.position.z), transform.rotation).GetComponent<rotation>().rotationSpeed=-100f;
Your answer
Follow this Question
Related Questions
Topdown Zelda-esque character controller help c# 3 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
transform.rotations not going past 90 and -90 degrees 0 Answers