Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question I need help to fix a problem I cant seem to locate on my script!? help would be appreciated!

Discussion in 'Scripting' started by BigBrainStudios, Nov 13, 2022.

  1. BigBrainStudios

    BigBrainStudios

    Joined:
    Mar 27, 2021
    Posts:
    1
    My Error Meassages are:

    Assets\Scripts\Fighter.cs(63,97): error CS1061: 'Animator' does not contain a definition for 'GetCurentAnimatorStateInfo' and no accessible extension method 'GetCurentAnimatorStateInfo' accepting a first argument of type 'Animator' could be found (are you missing a using directive or an assembly reference?)

    &

    Assets\Scripts\Fighter.cs(10,36): error CS0266: Cannot implicitly convert type 'float' to 'int'. An explicit conversion exists (are you missing a cast?)


    ___________________________________________________________________
    Also Note that im generaly new to scripting and to unity
    ___________________________________________________________________
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Fighter : MonoBehaviour
    6. {
    7.     private Animator anim;
    8.     public float cooldown = 2f;
    9.     private float nextFireTime = 0f;
    10.     public static int noOfClicks = 0f;
    11.     float lastClickedTime = 0;
    12.     float maxComboDelay = 1;
    13.  
    14.  
    15.     // Start is called before the first frame update
    16.     void Start()
    17.     {
    18.         anim = GetComponent<Animator>();
    19.     }
    20.  
    21.     // Update is called once per frame
    22.     void Update()
    23.     {
    24.         if(anim.GetCurrentAnimatorStateInfo(0).normalizedTime > 0.7f && anim.GetCurrentAnimatorStateInfo(0).IsName("hit1"))
    25.         {
    26.             anim.SetBool("hit1", false);
    27.         }
    28.         if (anim.GetCurrentAnimatorStateInfo(0).normalizedTime > 0.7f && anim.GetCurrentAnimatorStateInfo(0).IsName("hit2"))
    29.         {
    30.             anim.SetBool("hit2", false);
    31.         }
    32.         if (anim.GetCurrentAnimatorStateInfo(0).normalizedTime > 0.7f && anim.GetCurrentAnimatorStateInfo(0).IsName("hit3"))
    33.         {
    34.             anim.SetBool("hit3", false);
    35.             noOfClicks = 0;
    36.         }
    37.  
    38.         if(Time.time - lastClickedTime > maxComboDelay)
    39.         {
    40.             noOfClicks = 0;
    41.         }
    42.         if(Time.time > nextFireTime)
    43.         {
    44.             if(Input.GetMouseButtonDown(0))
    45.             {
    46.                 OnClick();
    47.             }
    48.         }
    49.  
    50.     }
    51.  
    52.     void OnClick()
    53.     {
    54.         lastClickedTime = Time.time;
    55.         noOfClicks++;
    56.         if(noOfClicks == 1)
    57.         {
    58.             anim.SetBool("hit1", true);
    59.         }
    60.  
    61.         noOfClicks = Mathf.Clamp(noOfClicks, 0, 3);
    62.  
    63.         if(noOfClicks >= 2 && anim.GetCurrentAnimatorStateInfo(0).normalizedTime > 0.7f && anim.GetCurentAnimatorStateInfo(0).IsName("hit1"))
    64.         {
    65.             anim.SetBool("hit1", false);
    66.             anim.SetBool("hit2", true);
    67.         }
    68.         if(noOfClicks >= 3 && anim.GetCurrentAnimatorStateInfo(0).normalizedTime > 0.7f && anim.GetCurrentAnimatorStateInfo(0).IsName("hit2"))
    69.         {
    70.             anim.SetBool("hit2", false);
    71.             anim.SetBool("hit3", true);
    72.         }
    73.  
    74.     }
    75.  
    76.  
    77. }
    78.  



     
  2. BorpaBoatski

    BorpaBoatski

    Joined:
    Aug 3, 2018
    Posts:
    54
    Looks like you've misspelled "CurrentAnimatorStateInfo" as "CurentAnimatorStateInfo" at line 63. (Your spelling is missing an extra 'r').

    As for the cast. You've created an int noOfClicks but initialized the value as a float with the 'f' after the 0. Removing the 'f' should fix it.

    Also, it looks like you've posted in the wrong section. This section is for Visual Scripting not just general scripting.
     
    Last edited: Dec 16, 2022