Hey there, i’m pretty new at scripting.
I’m working on a project, my scene is made up of the following.
A Sphere in located in the middle of the scene, and 4 other spheres are orbiting around the center sphere.
I have a camera focusing on the center object that can rotate around it and zoom in and out with smooth motion.
My problem is that i want to make a script that will allow me to click on one of the 4 sphere in orbit, to where the sphere that i selected will move in and replace the center sphere, and the center sphere will move out, and orbit the new center sphere.
Could anyone provide me with a script can do want i’m asking for?
or just help me make one?
You could use it to detect whether you clicked on a sphere - something like:
var target : Transform;
var MoveSpeed : float = 2;
function OnMouseDown () {
transform.LookAt(target);
transform.position += transform.forward * MoveSpeed * Time.deltaTime;
}
This script would then need to be added to each sphere!
This is just a quick idea, there is for example a problem = since the transform.position part is not in the Update function, the sphere won’t move forwards properly…
It should be simple enough to move the transform.position etc part to the Update, but tell me if you need help with that…
The “transform.LookAt(target);” part is to make sure the sphere is looking at the center sphere and could perhaps also be placed into the Update function!
Also, you will have to assign the center sphere to the “target” variable in the Inspector window.
Good luck!