- Home /
Moving an object with Clicking GUI Button
Hello, i have some problem with moving an object with GUI Button i had search and tried a lot of ways but it not successful..
What i tried to do is, how to make an object move(not snapping) into some point i appointed with GUI Button click..
i make the GUI, and i make this code
function OnGUI() {
if(GUI.Button(Rect(50,300,70,30),"Attack 1")){
GameObject.Find("brawler_armoured").transform.position.x = -7;
GameObject.Find("brawler_armoured").transform.position.y = -1.5;
//Controller.Move(MoveSpeed*5) * Time.deltaTime;
}
}
with this code, my object could change position, to the point, but what i want is they move to there.. i really confused, my friend ask me to use time.deltatime.. but every time i look for the tutorial all using function Update() and the tutorial always about w,a,s,d key..
please anyone help me,, or if it's aldy answered and the problem is just the same, please give me the link :) thanks before.
Answer by vividhelix · Nov 23, 2013 at 04:32 PM
Easiest thing is to use a tweening library, such as HOTween or iTween. They have movement functions, both their documentation is pretty good.
Alternatively, you could lerp the location yourself, the example here is pretty close to what you're looking for: http://docs.unity3d.com/Documentation/ScriptReference/Vector3.Lerp.html
Thanks vivid for the answer, but i think i dont go with motion first, i want so that when i click my gui button it move.. and ur examples is placed on update()..
the matter here is, the javascript file will attached to player, but $$anonymous$$e is attached to $$anonymous$$ain Camera.. and i'd like to know how to put my code on $$anonymous$$ain Camera, since my GUI is in my $$anonymous$$ain Camera..