I’m doing the ‘Roll-a-Ball’ tutorial, and everything works fine, until adding the part where the Player collides with a cube, and the cube disappears. (#5: Creating Pickup Objects).
The Player collided with the Pickup Objects, in the previous step, but now it rolls right thru 'em. It appears no “OnTriggerEnter” is being registered.
Here is the Player Script:
(Just added the GUIText, and the counter stays at (0)zero)
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public float speed;
public GUIText countText;
private int count;
void Start ()
{
count = 0;
SetCountText ();
}
void FixedUpdate()
{
float moveHorizonatal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizonatal, 0.0f, moveVertical);
rigidbody.AddForce(movement * speed * Time.deltaTime);
}
void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "Pickup")
{
other.gameObject.SetActive(false);
count = count + 1;
SetCountText ();
}
}
void SetCountText()
{
countText.text = "Count: " + count.ToString();
}
}
Any help is greatly appreciated. Never worked in C# before.
Thanks!