unity-towers-of-hanoi/Assets/Controls.cs

36 lines
816 B
C#
Raw Normal View History

2019-03-04 09:27:27 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Controls : MonoBehaviour
{
2019-03-05 22:57:02 +00:00
public GameObject control;
private int separation = 8;
private Vector3 position = new Vector3(0, 10, 0);
2019-03-04 09:27:27 +00:00
// Update is called once per frame
void Update()
{
2019-03-05 22:57:02 +00:00
if (Input.GetKeyUp("a"))
{
if (this.position.x > -1)
{
this.position.x = this.position.x - this.separation;
}
}
if (Input.GetKeyUp("d"))
2019-03-04 09:27:27 +00:00
{
2019-03-05 22:57:02 +00:00
if (this.position.x < 1)
{
this.position.x = this.position.x + this.separation;
}
2019-03-04 09:27:27 +00:00
}
}
2019-03-05 22:57:02 +00:00
void FixedUpdate()
{
this.control.transform.position = this.position;
}
2019-03-04 09:27:27 +00:00
}