Hi guys, I have tried just about EVERY solution I have found online and havent gotten any positive results on why it is that my 2D trigger-based collision is not working.
’
Result of execution: turtle goes right through the gold piece without disabling it.
using UnityEngine;
alt text using System.Collections;
public class playerScript : MonoBehaviour {
public Rigidbody2D rb;
public float speed;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody2D> ();
}
// Update is called once per frame
void FixedUpdate () {
if (Input.GetKeyDown (KeyCode.Space)) {
Debug.Log ("Space key was pressed.");
rb.AddForce (new Vector3 (0, 300, 0));
} else if (Input.GetKey (KeyCode.RightArrow) && Input.GetKeyDown (KeyCode.Space)) {
Debug.Log ("Space key and Right Key.");
rb.AddForce (new Vector3 (10, 30, 0));
} else if (Input.GetKey (KeyCode.RightArrow)) {
Debug.Log ("Right key was pressed.");
rb.AddForce (new Vector3 (10, 0, 0));
} else if (Input.GetKey (KeyCode.LeftArrow)) {
Debug.Log ("Right key was pressed.");
rb.AddForce (new Vector3 (-10, 0, 0));
} else if (Input.GetKey (KeyCode.LeftArrow) && Input.GetKeyDown (KeyCode.Space)) {
Debug.Log ("Space key and Left Key.");
rb.AddForce (new Vector3 (-10, 30, 0));
}
}
void onTriggerEnter(Collider other) {
if (other.gameObject.CompareTag ("Pick Up"))
{
other.gameObject.SetActive (false);
}
}
}