Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Help with c#! functions not being called.

Discussion in 'Scripting' started by HarpDernier, Sep 20, 2014.

  1. HarpDernier

    HarpDernier

    Joined:
    May 30, 2013
    Posts:
    6
    I have this script on an object that's a child to the character with just this script, a box collider and an audio source. The CD is a collectable. It's not playing the audio file or adding the value to the variable. It won't show the debug log either.


    using UnityEngine;
    using System.Collections;

    public class CdController : MonoBehaviour
    {
    public GUISkin theSkin;

    public AudioClip CDPickUp;

    float cDS = 0;

    void OnGUI()
    {
    GUI.skin = theSkin;
    GUI.Label (newRect (Screen.width / 2 - 300, 110, 200, 200), "" + Mathf.Floor(cDS));
    }

    void OnTriggerEnter2D (Collider2D info)
    {
    if (info.tag == "Collectable")
    {
    audio.PlayOneShot(CDPickUp);
    cDS += 100;
    Debug.Log("Good");
    }
    }
    }
     
  2. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    - make sure the tag is spelled exactly the same
    - make sure your box collider is a 2D collider and has checked 'isTrigger'

    You could also put another Debug.Log("bla") into the trigger function in order to check whether it works so far or doesn't even fire that one.

    *Edit: Please use code tags.
     
  3. HarpDernier

    HarpDernier

    Joined:
    May 30, 2013
    Posts:
    6
    Thanks a lot! I had checked a million times but I checked once more and the "c" was capitalized when it shouldn't have been.
     
    Suddoha likes this.