Вот скрин:
как заставить не проходить сквозь коллайдер? rigidBody стоит. Вот скрипт контроллера:
Код
using UnityEngine;
public class PlayerControl : MonoBehaviour {
private GameObject Player;
public float Speed = 0.01f;
//private bool Wall=false;
private Animator AnimControll;
// Use this for initialization
void Start () {
Player = this.gameObject;
AnimControll = gameObject.GetComponent<Animator>();
}
[Space]
public bool btnUp=false;
public bool btnDown = false;
public bool btnLeft = false;
public bool btnRight = false;
// Update is called once per frame
public void Update () {
Up();
Down();
Left();
Right();
if (!btnDown & !btnLeft & !btnRight & !btnUp)
{
AnimControll.Play("idle");
}
}
private void OnCollisionEnter2D(Collision collision)
{
Player.transform.position = new Vector2(Player.transform.position.x - Speed, Player.transform.position.y - Speed);
}
public void Up()
{
if ((Input.GetButton("Up")&!Input.GetButton("Left")& !Input.GetButton("Right"))||(btnUp))
{
AnimControll.Play("walk_w");
Player.transform.position = new Vector2(Player.transform.position.x, Player.transform.position.y + Speed);
}
}
public void Down()
{
if ((Input.GetButton("Down") & !Input.GetButton("Left") & !Input.GetButton("Right"))||(btnDown))
{
AnimControll.Play("walk_s");
Player.transform.position = new Vector2(Player.transform.position.x, Player.transform.position.y - Speed);
}
}
public void Left()
{
if (Input.GetButton("Left")||btnLeft)
{
AnimControll.Play("walk_a");
Player.transform.position = new Vector2(Player.transform.position.x - Speed, Player.transform.position.y);
}
}
public void Right()
{
if (Input.GetButton("Right")||btnRight)
{
AnimControll.Play("walk_d");
Player.transform.position = new Vector2(Player.transform.position.x + Speed, Player.transform.position.y);
}
}
}