Hi. I’m experimenting with making it so that the first left mouse click has the player appear at one Vector3,
and then the second left mouse click makes the player appear at a different Vector3.
It sounds simple, and I am definitely not a good coder, but have been trying to teach myself for awhile.
I’ve gone through two approaches to the code so far, which I’ll add so people can see my approaches.
Any feedback about potential directions to apply would be welcome.
using UnityEngine;
using System.Collections;
public class TwoClicks : MonoBehaviour {
public GameObject player;
public bool buttonPressed;
// Use this for initialization
void Start () {
buttonPressed = false;
}
// Update is called once per frame
public void FirstClick() {
if (Input.GetMouseButtonDown(0))
{
player.transform.position = new Vector3(3, 3, 0);
buttonPressed = true;
SecondClick();
}
}
public void SecondClick()
{
if (Input.GetMouseButtonDown(0))
{
player.transform.position = new Vector3(-3, 2, 0);
}
}
}
using UnityEngine;
using System.Collections;
public class UpButton : MonoBehaviour
{
public GameObject player;
public Vector3 Initial = player.transform.position;
public enum State
{
Idle,
StageOne,
StageTwo
}
public State _state;
// Use this for initialization
void Start()
{
GetComponent<Transform>();
switch (_state)
{
case State.Idle:
Idle();
break;
case State.StageOne:
StageOne();
break;
case State.StageTwo:
StageTwo();
break;
}
}
public void Idle()
{
player.transform.position = Initial;
if (Input.GetMouseButtonDown(0))
{
StageOne();
}
}
public void StageOne()
{
player.transform.position = new Vector3(3, 3, 0);
if (Input.GetMouseButtonDown(0))
{
StageTwo();
}
}
public void StageTwo()
{
player.transform.position = new Vector3(-3, 2, 0);
}
}