Search Unity

Animation won't play in all my prefabs

Discussion in 'Scripting' started by Deleted User, Jan 9, 2019.

  1. Deleted User

    Deleted User

    Guest

    Hi, I'm trying to make several objects rotate, when I press the Vuforia Virtual button... I created a prefab, but only the one that is added to the inspector is the one that rotates... what can I do please?...

    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using Vuforia;
    6.  
    7. public class vbButton : MonoBehaviour, IVirtualButtonEventHandler {
    8.  
    9.     public GameObject vbBtnObj;
    10.     public Animator cubeAni;
    11.  
    12. // Use this for initialization
    13. void Start () {
    14.         vbBtnObj = GameObject.Find("VirtualBtn");
    15.         vbBtnObj.GetComponent<VirtualButtonBehaviour>().RegisterEventHandler(this);
    16.         cubeAni.GetComponent<Animator>();
    17. }
    18.     public void OnButtonPressed(VirtualButtonBehaviour vb)
    19.     {
    20.         cubeAni.Play("cube_animation");
    21.         Debug.Log("Button pressed");
    22.     }
    23.  
    24.     public void OnButtonReleased(VirtualButtonBehaviour vb)
    25.     {
    26.         cubeAni.Play("none");
    27.         Debug.Log("Button released");
    28.     }
    29. }