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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Reall noob question

Discussion in 'Scripting' started by Khofnak, Apr 22, 2016.

  1. Khofnak

    Khofnak

    Joined:
    Mar 3, 2015
    Posts:
    21
    i want to trigger animations cant seem to find error glass one does not seem to work can somebody point out what am i doing wrong


    using UnityEngine;
    using System.Collections;

    public class doorwala : MonoBehaviour {
    public Animator ani;
    public int i;



    // Use this for initqialization
    void Start () {

    }


    void OnTriggerEnter (Collider other){
    if (other.gameObject.tag == "player") {
    if (i < 5) {
    ani = GameObject.FindWithTag ("trigger").GetComponent<Animator> ();

    ani.SetInteger ("b", i);
    } else {
    ani = GameObject.FindWithTag ("glass").GetComponent<Animator> ();

    ani.SetInteger ("test", i);
    }
    }

    }

    /* void OnTriggerExit (Collider other){
    if (other.gameObject.tag == "Player") {
    i = 2;
    ani.SetInteger ("b", i);
    }
    }*/
    // Update is called once per frame
    void Update () {

    }
    }
     
    Last edited: Apr 22, 2016
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
  3. Jymmy097

    Jymmy097

    Joined:
    Jul 7, 2014
    Posts:
    67
    Mmhh... The code that handles the variable i would be useful to determine the problem. However, you may try to do something to correct the bug:
    1. Put a Debug.Log("Glass") in the else branch in order to understand if it's executed.
    2. You can try to use the technique in 1 outputting the value of ani (try to see if it's null or not)
    3. If you're using MonoDevelop (or VS with VS tools), you may try to start debugging to inspect the problem
    Finally, I'd advise you not to use GameObject.FindWithTag if it's not necessary: if the GameObject you want to look for is present in the scene at the time you're instantiating the GameObject that has this component, you can use a global variable to hold it and get a faster access to it.

    Hope this helps...

    Jymmy097
     
  4. Khofnak

    Khofnak

    Joined:
    Mar 3, 2015
    Posts:
    21
    i have tried Debug.log but even if the condition is true it never executes the animation clip

    upload_2016-4-22_23-31-12.png

    upload_2016-4-22_23-25-15.png upload_2016-4-22_23-25-54.png