I am completely new to unity as well as java script. Maybe my question makes you laugh but I want your help. I have 4 cubes and each cube has its own script file. I am using java script. I want to control rotation of cube1 from cube3 and vice versa. and also have to add add force in it. how can I do that?
Thanks in advance!
I’m not really sure if it works properly. I don’t really know javascript. But it will help you.
First you need to create variables for cubes.
public var cube1 : GameObject;
public var cube2 : GameObject;
public var cube3 : GameObject;
you’ll assign the cubes from inspector panel. Don’t forget.
To rotate you can simply use
cube1.transform.Rotate(Vector3.right * Time.deltaTime);
this will slowly rotate
cube1.transform.rotation= Quaternion(90,0,0,0);
this will set the exact rotatiton of cube1(that you attached on inspector)
To use addForce
cube1.GetComponent(Rigidbody).AddForce(transform.forward*300);