Search Unity

Disable animation by cursor visible

Discussion in 'Scripting' started by Timoty75, Jan 21, 2019.

  1. Timoty75

    Timoty75

    Joined:
    May 29, 2017
    Posts:
    150
    Hi gys I have a problem: I created a script that when I press a key the cursor get visiblee or not (see attacked script, and a animator whit animations by Fire1 and Fire2. I would that my animation (when I press Fire 1) become disable when the cursor is visible. How can I change a script? thank a lot.




    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class cursor : MonoBehaviour
    6. {
    7.  
    8.     public bool Hidemouse = true;
    9.     public Animator adam;
    10.     // Start is called before the first frame update
    11.     void Start()
    12.     {
    13.         adam = gameObject.GetComponent<Animator>();
    14.     }
    15.  
    16.     // Update is called once per frame
    17.     void Update()
    18.     {
    19.         if (Input.GetKeyDown(KeyCode.Y))
    20.             adam.SetBool("attack", false);////is it true?
    21.         {
    22.             Hidemouse = !Hidemouse;
    23.         }
    24.         Cursor.lockState = Hidemouse ? CursorLockMode.Locked : CursorLockMode.None;
    25.         Cursor.visible = !Hidemouse;
    26.  
    27.     }
    28. }
    29.  
    30.