Make button move character?
So I have a button on the screen. I want the button to move the character whenever its pressed.
Here's the code i have so far
public void left(string leftcircle) {
GetComponent<Transform> ().RotateAround (Vector3.zero, Vector3.forward, -xRotate); //= Quaternion.Euler (0, 0, xRotate);
}
This is attached to the button so obviously whenver it is pressed, the actual button moves. So is there a way to tell it to move the object and not the actual button?
Answer by UniqueMAX · Jan 13, 2016 at 03:51 AM
Attach the script to the object you want to move, not to the button. Then choose your button, in its options find the OnClick() box, press "+". The line consisting of an input field will appear. Drag and drop the object to this field, then click the combobox to the right from the field and find a line that's called "left".
@Unique$$anonymous$$AX
Thanks for the quick answer!
Quick question though. Is there a way to make it that when you press and hold the ubtton, the character rotates. Because right now, when you press it the object only moves a little bit. So now you have to keep pressing the button repeatedly, but I just want it to be held down.
I don't know for sure. I could only suggest another mechanics: You press the button once and object starts rotating continuosly. You press it again and it stops. If that fits your requirements I can post code sample. For hold function you should search more
No that wouldn't work for the game. Since I'm porting this to a touch device. Is it possible to add a sprite with box collider and when the player touches inside the sprite, the rotation begins?