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

what is wrong with this script

Discussion in 'Scripting' started by Hard target, Aug 8, 2014.

  1. Hard target

    Hard target

    Joined:
    Oct 31, 2013
    Posts:
    132
    This c sharp script won't stop my walk animation.I animated my character with the animation window.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class switchanimation : MonoBehaviour {
    5.  
    6.     void OnTriggerEnter(Collider other) {
    7.         if (other.CompareTag("Player"))
    8.             animation.Play("angyx Animation");
    9.         animation.Play("angyx Animation", PlayMode.StopAll);
    10.      
    11.      
    12.      
    13.     }
    14. }
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
  3. Hard target

    Hard target

    Joined:
    Oct 31, 2013
    Posts:
    132
    I tried both of those and it did not work.
     
  4. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Ensure your OnTriggerEnter method is actually being called and the thing being collided with is tagged as Player
     
  5. Hard target

    Hard target

    Joined:
    Oct 31, 2013
    Posts:
    132
    How would i ensure my ontrigger method is actually being called?I have the cube with the Player tag parented to the npc.
     
  6. pumpkinszwan

    pumpkinszwan

    Joined:
    Feb 6, 2014
    Posts:
    214
    Just put a Debug.Log("Ontrigger being called here"); or similar in the method.
     
  7. Hard target

    Hard target

    Joined:
    Oct 31, 2013
    Posts:
    132
    It say's Animation event ontriggerenter has no receiver are you missing a component.So what is stopping it from working.
     
    Last edited: Aug 9, 2014
  8. Hard target

    Hard target

    Joined:
    Oct 31, 2013
    Posts:
    132
  9. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    You need to post the exact error message. It sounds as if the game object doesn't contain an animation component.