скрипт:
Синтаксис:
Используется csharp
using UnityEngine;
using System.Collections;
public class Script : MonoBehaviour
{
public Texture2D ButtonImage = null;
public float speed = 3f;
public int move = 0;
void Update()
{
if (move == 1) transform.Translate(-Vector3.right * speed * Time.deltaTime);
else if (move == 2) transform.Translate(-Vector3.left * speed * Time.deltaTime);
}
void OnGUI()
{
Rect rightRect = new Rect(350, 0, 500, 5000);
Rect leftRect = new Rect(0, 0, 350, 5000);
Event e = Event.current;
if (e.type == EventType.MouseDown && e.button == 0)
{
if (rightRect.Contains(e.mousePosition)) move = 1;
else if (leftRect.Contains(e.mousePosition)) move = 2;
}
if (e.type == EventType.MouseUp && e.button == 0) move = 0;
GUI.Button (rightRect, "Right");
GUI.Button(leftRect, "Left");
if
}
}
using System.Collections;
public class Script : MonoBehaviour
{
public Texture2D ButtonImage = null;
public float speed = 3f;
public int move = 0;
void Update()
{
if (move == 1) transform.Translate(-Vector3.right * speed * Time.deltaTime);
else if (move == 2) transform.Translate(-Vector3.left * speed * Time.deltaTime);
}
void OnGUI()
{
Rect rightRect = new Rect(350, 0, 500, 5000);
Rect leftRect = new Rect(0, 0, 350, 5000);
Event e = Event.current;
if (e.type == EventType.MouseDown && e.button == 0)
{
if (rightRect.Contains(e.mousePosition)) move = 1;
else if (leftRect.Contains(e.mousePosition)) move = 2;
}
if (e.type == EventType.MouseUp && e.button == 0) move = 0;
GUI.Button (rightRect, "Right");
GUI.Button(leftRect, "Left");
if
}
}