Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Roll-A-Ball tutorial collision/trigger problem

Discussion in 'Scripting' started by MrDArkHeArT, Dec 30, 2014.

  1. MrDArkHeArT

    MrDArkHeArT

    Joined:
    Dec 30, 2014
    Posts:
    3
    I am a beginner in Unity and am taking the roll-a-ball tutorial and everything was smooth but when I got to section 06 of the tutorial my pickups didn't work. the player just passes through the cubes and they don't disappear as they did in the tutorial video.

    here is my PlayerController script

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerController : MonoBehaviour
    5. {
    6.  
    7.     public float speed;
    8.  
    9.     void FixedUpdate ()
    10.     {
    11.         float moveHorizontal = Input.GetAxis ("Horizontal");
    12.         float moveVertical = Input.GetAxis ("Vertical");
    13.  
    14.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    15.  
    16.         rigidbody.AddForce (movement * speed * Time.deltaTime);
    17.     }
    18.  
    19.     void OnTriggerEnter(Collider other)
    20.     {
    21.         if(other.gameObject.tag == "PickUp")
    22.         {
    23.             other.gameObject.SetActive(false);      
    24.         }
    25.     }
    26. }
    27.  
    P.S. I ticked Is Kinematic and Is trigger
     
  2. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Have you assigned the 'PickUp', tag to the pickup prefab after adding it to the tag list?
    have a wee look and see that the tags are there in the scene on the cubes.
     
  3. MrDArkHeArT

    MrDArkHeArT

    Joined:
    Dec 30, 2014
    Posts:
    3
    Yes I did and I just found the problem thanks to you, I just noticed that I spelled PickUp in the script with a small "p" at the end, but it was a capital "P" in the tag.

    Thanks for the help :D

    sorry for the late reply; had exams
     
    OboShape likes this.
  4. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    nice one :)