Hello,
How are you?
I'm justing trying to understand the basics of collision with 2D Toolkit.
I have two sprites and I'm able to move the player with a script, the question is... When I imported the sprite at Sprite Collection I put it as box trimmed, When a sprite get above the other, how to detect the collision event and give a command?
My code:
~using UnityEngine;
using System.Collections;
public class FishMovement : MonoBehaviour {
public float speed = 0.5f;
void OnCollisionEnter(Collision collision)
{
//if (collision.gameObject.tag == "Eletric") {
Application.Quit ();
// }
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
if (Input.GetKey(KeyCode.LeftArrow))
{
transform.position += Vector3.left * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.RightArrow))
{
transform.position += Vector3.right * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.UpArrow))
{
transform.position += Vector3.up * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.DownArrow))
{
transform.position += Vector3.down * speed * Time.deltaTime;
}
}
}
I've already added a RigidBody at the Sprite but its not working...
Greetings