So I made a simple 2D setting where you can move a block.
But I can not completely snap to another sprite (wall).
Screenshot:
Inspector settings wall/player:
PlayerMovement Script:
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
public KeyCode moveUp;
public KeyCode moveDown;
public KeyCode moveLeft;
public KeyCode moveRight;
public float speed = 10f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void FixedUpdate () {
Vector2 v = rigidbody2D.velocity;
if (Input.GetKey (moveUp)) {
v.y = speed;
v.x = 0;
rigidbody2D.velocity = v;
} else if (Input.GetKey (moveDown)) {
v.y = speed * -1;
v.x = 0;
rigidbody2D.velocity = v;
} else if (Input.GetKey (moveRight)) {
v.x = speed;
v.y = 0;
rigidbody2D.velocity = v;
} else if (Input.GetKey (moveLeft)) {
v.x = speed * -1;
v.y = 0;
rigidbody2D.velocity = v;
}
else
{
v.x = 0;
v.y = 0;
rigidbody2D.velocity = v;
}
}
}
These are the files I’m using:
Player: Microsoft OneDrive - Access files anywhere. Create docs with free Office Online.
Wall: Microsoft OneDrive - Access files anywhere. Create docs with free Office Online.
I have no idea what can create this space because the this is my first unity game. Thanks in advance!!