i have a rocket and some planets, i have attached colliders on both and both are rigid bodies.
but i am not able to detect collisions. here is the script .PLEASE HELP!!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
public class RocketController : MonoBehaviour {
public float speed;
private Rigidbody2D rgbd;
// Use this for initialization
void Start () {
rgbd = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update () {
Vector2 moveVec = new Vector2(CrossPlatformInputManager.GetAxis("Horizontal"),
CrossPlatformInputManager.GetAxis("Vertical"));
Debug.Log(moveVec);
Vector3 lookVec = new Vector3(CrossPlatformInputManager.GetAxis("Horizontal"),
CrossPlatformInputManager.GetAxis("Vertical"), 4000);
transform.rotation = Quaternion.LookRotation(lookVec, Vector3.back);
transform.Translate(moveVec * Time.deltaTime * speed, Space.World);
}
private void OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.tag=="planet")
{
Destroy(collision.gameObject);
}
}