Скрипт, исправьте пожалуйста
Синтаксис:
Используется csharp
using UnityEngine;
using System.Collections;
public class Script : MonoBehaviour
{
public Texture2D ButtonImage = null;
public float speed = 3f;
public int move = 0;
private bool facingRight = true;
void Update()
{
if (move == 1) transform.Translate(-Vector3.right * speed * Time.deltaTime);
else if (move == 2) transform.Translate(-Vector3.left * speed * Time.deltaTime);
if (move == 1 && !facingRight)
Flip();
else if (move == 2 && facingRight)
Flip();
}
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;
}
void Flip()
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
using System.Collections;
public class Script : MonoBehaviour
{
public Texture2D ButtonImage = null;
public float speed = 3f;
public int move = 0;
private bool facingRight = true;
void Update()
{
if (move == 1) transform.Translate(-Vector3.right * speed * Time.deltaTime);
else if (move == 2) transform.Translate(-Vector3.left * speed * Time.deltaTime);
if (move == 1 && !facingRight)
Flip();
else if (move == 2 && facingRight)
Flip();
}
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;
}
void Flip()
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}