Search Unity

Animation plays automatically

Discussion in 'Animation' started by GulnurSezen, Jan 6, 2022.

  1. GulnurSezen

    GulnurSezen

    Joined:
    Jan 6, 2022
    Posts:
    1
    Hello everyone, I have a problem. When I press a button in the panel, I want the panel to slide away with the button and another panel to come.
    But when I press the first button, the panel I want opens, while the other panel does not go. All the codes I wrote for the animation of the panel do not work.
    I am trying to make an android application. I am associating the code with the menu. The code plays automatically when I press the play button. How do I prevent this? Can you check my code?
    I have another question, how can I combine animations of different objects in one code. For example, I will press the button and the panel will move to the right with a small animation, and another panel will appear. This event needs to be specific for each button.

    Thank you in advance for your help and advice.



    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class MainMenuGoes : MonoBehaviour
    6. {
    7.  
    8.     // Animator component reference
    9.     Animator MainView;
    10.  
    11.     // Use this for initialization
    12.     void Start()
    13.     {
    14.         // Getting game objects animator component
    15.         MainView = GetComponent<Animator>();
    16.     }
    17.  
    18.     // Update is called once per frame
    19.     void Update()
    20.     {
    21.         // getting a touch and its position from input
    22.         if (Input.touchCount > 0)
    23.         {
    24.             Touch touch = Input.GetTouch(1);
    25.             Vector3 touchPos = Camera.main.ScreenToWorldPoint(touch.position);
    26.  
    27.      
    28.                     if (GetComponent<BoxCollider2D>() == Physics2D.OverlapPoint(touchPos))
    29.                     {
    30.                         MainView.SetTrigger("MainGoes");
    31.                     }
    32.          
    33.         }
    34.     }
    35. }
    36.  
     
    Last edited: Jan 7, 2022