- Home /
How can I stick buttons on my cube and the same time using script?
Please help me I've been trying to figure out this for a month now...Yeah embarrassing... Well I have a cube with a script for rotating it and my problem is that I wan't to put buttons or idk something similar like "Piano Tiles" on the cube and still use my script for rotating it and also the buttons to be pressed. Please help me solve this issue I am new to game developing and C#.
Also if the code is bad I tried to make a code for touch dragging and rotating my cube feel free to make a brand new code.
Heres my code:
private float rotationSpeed = 8.0F;
private float lerpSpeed = 1.0F;
private Vector3 theSpeed;
private Vector3 avgSpeed;
private bool isDragging = false;
private Vector3 targetSpeedX;
void OnMouseDown() {
isDragging = true;
}
void Update() {
if (Input.GetMouseButton(0) && isDragging) {
theSpeed = new Vector3(-Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"), 0.0F);
avgSpeed = Vector3.Lerp(avgSpeed, theSpeed, Time.deltaTime * 0);
} else {
if (isDragging) {
theSpeed = avgSpeed;
isDragging = false;
}
float i = Time.deltaTime * lerpSpeed;
theSpeed = Vector3.Lerp(theSpeed, Vector3.zero, i);
}
transform.Rotate(Camera.main.transform.up * theSpeed.x * rotationSpeed, Space.World);
transform.Rotate(Camera.main.transform.right * theSpeed.y * rotationSpeed, Space.World);
my problem is that I wan't to put buttons or idk something similar like "Piano Tiles" on the cube and still use my script for rotating it and also the buttons to be pressed.
What exactly is the problem, what stops you from doing that?
@doublemax Thank you for replying. Well I did add 2D Box Collider to all piano tiles but the main cube has regular Box Collider. And also can you tell me how to code the piano press... Oh and I want it to press when the rotation dragging is stopped and only short touches will press the tiles.If I touch and hold I want it to rotate if i just press once it will click and turn red on a tile etc...If you don't want to give me code please post some tutorials or something similar so I can make this. Thanks again for helping me xD
@doublemax I don't know how to put like piano tiles on a cube and use the script above for rotation at the same time. Can you explain the easiest way to do it ?
For the "piano tiles" you could just create new cubes as children of the big one, scale them accordingly and place them onto the cube.
The question is: If the user touches these tiles, what is supposed to happen? Shall it rotate the cube or should something else happen?
@doublemax Well I did that but I can't rotate the cube because I can't touch the big one because of the smaller cubes... I wan't to be able to still rotate the Cube and when I am not dragging with touch I want Piano tiles on the cube and just press them like buttons etc... This is my first game so thank you for helping me build it...
I don't know how to put like piano tiles on a cube.Can you explain the easiest way to do it ? @doublemax
Your answer
Follow this Question
Related Questions
Unity project on android - OnPointerDown/Up movement 1 Answer
Unity Android fetching wrong screen resolution 1 Answer
how to describe a android path in c# script 1 Answer
Dialouge isnt working 1 Answer
Google Daydream Thread with Unity 1 Answer