- Home /
Question by
$$anonymous$$ · May 21, 2014 at 07:16 PM ·
c#movementaxis
Z axis change
Ok, so I am trying to find the best way to move an object from foreground to background. I know I can use axis input, but I was wondering if there was a way that say, when I hit a button it would set the z axis to a certain value, then hit a different button to move it back? Any input is great! (Btw I'm using c#)
Comment
Sounds like you want Get$$anonymous$$eyDown or GetButtonDown.
Best Answer
Answer by kamgru123 · May 21, 2014 at 07:34 PM
This is not tested, but should work. Just add this script to your object, and also add a collider.
public test : MonoBehaviour
{
public float back = 1;
public float front = -1;
private bool isfront;
void OnMouseDown()
{
if (!isfront)
{
transform.position = new Vector3(transform.position.x,
transform.position.y, front);
isfront = true;
}
else
{
transform.position = new Vector3(transform.position.x,
transform.position.y, back);
isfront = false;
}
}
}
Your answer
Follow this Question
Related Questions
Making a bubble level (not a game but work tool) 1 Answer
Axis Issue 1 Answer
Distribute terrain in zones 3 Answers
Can't change the speed of a character. 2 Answers
adiing a wait betweem if statements 1 Answer