Hey guys! I am pretty new to C# and am currently making my second game using this language. I am stuck as an error is being shown in the console. The animations doesn´t work. I have this warning: Parameter 'Istouching' does not exist. UnityEngine.Animator:SetBool (string,bool) Muelle:Update () (at Assets/Scripts/Muelle.cs:23) I explain; I have been developing the functionality of a dock in unity, and I have used this script to program it. Everything works correctly, the problem is when configuring the animations. What I have done has been to create a variable of type bool called is touching with that it will know when the player touches the dock with his tag. I have also configured the animator so that the animations are displayed at the correct time. Dock ---> Dock stretching when istouching = true Dock stretching ---> Dock when istouching = false I am Spanish, my English is a bit bad. Thanks to anyone who can help Muelle = dock . Muelle estirado = dock stretching captura-de-pantalla-175.png (204.3 kB) captura-de-pantalla-174.png (145.3 kB)
It would help to see the screenshot of your Animator. The code looks ok, is the name "Istouching" spelled correctly? Keep in mind that it is case-sensitive.
As was said above, it's case-sensitive. The animator has a lower-case "i". You're setting it with an upper case "I". "istouching" NOT "Istouching"
Care to elaborate on what this means? You're saying it's still telling you that it cannot find "istouching"?
No, not that, that's obviously the bool state. Sorry, on the device I was looking at your image, the GameObject looked disabled. Now I'm on a bigger screen it's clear it's not. Only thing I can guess is that you're somehow referring to the wrong animator but that's just a guess.
What I literally did was create a bouncing material for the spring. Since the bounce it was doing was too powerful, I decided to script inside the dock to limit the height. Also insert the script into the player. Then for the animations create one with the normal spring and another with the stretched spring. I put the conditions with us "istouching" and modify the script.
As @MelvMay said, are you referring to the correct animator? Also, check if the animator parameter does not have white space character at the end like this "istouching ".
Obviously it means you're referring to a specific animator in your code. Does that animator have the animation you're actually showing above? In none of your images do you show this.
Have you assigned the transitions to activate depending on the status of the bool? Maybe that warning pops up if they arent assigned yet.
Okay, I think i know what is going on. You are setting the bool to equal istouching in update on every frame. It is probably resetting the animation trigger each frame so it is never occurring. I would remove the anim.SetBool line in update entirely. Then, in your OnCollisionEnter2D just get rid of the istouching = true/false and replace it with anim.SetBool("istouching", true) and false. Additionally, in the else condition you are setting it to false if the tag isnt "Muelle". It could be that when the player is on it that the collider is also touching another gameobject that doesnt have that tag. So...I would remove the else part and then create another function using OnCollisionExit2D to set the anim.SetBool to false. Last thing, add in some debug.logs to each if/else that you have to determine if everything/anything is actually running and to see if the bool is true/false when it should be true/false. Edit: The reason i believe this is cause you are getting a Yellow warning, not a Red error. The error would make it not work, the warning doesnt mean its null or not compiling, it is kinda just for cleaning up code that is unnecessary.
Try this: Code (CSharp): public float AlturaMaxima; private Rigidbody2D rb2d; private Animator anim; void Start() { rb2d = GetComponent<Rigidbody2D>(); anim = GetComponent<Animator>(); } void OnCollisionEnter2D(Collision2D col) { if(col.gameObject.tag == "Muelle") { anim.SetBool("istouching", true); Debug.Log("istouching should be true right now"); rb2d.velocity = new Vector2(rb2d.velocity.x, AlturaMaxima); } } void OnCollisionExit2D(Collision2D col) { if (col.gameObject.tag == "Muelle") { anim.SetBool("istouching", false); Debug.Log("istouching should be FALSE and player is no longer colliding"); } }
Its okay, we were all newbies at one point. I combined the anim.SetBool with the rb2d.velocity line because they are using the same If condition. What you did wasnt technically wrong, but its not clean code.
Btw have you checked the white space character? Another thing that is worth trying: hit the ctrl+s with Animator selected - maybe it needs to be serialized.
I already solved the error, I had made a mistake in one thing when writing the code. Anyway the animation still does not work.
Okay. Run the scene, have the animator window open at the same time, and manually change the bool in the parameters tab. Does the animation work that way? If it does, verify the spelling of the bool, like Epsilon_Delta mentioned. You may have a space before or after "istouching" in the parameters tab of the animator window and it has to be exact. One way of figuring this out is to double click or click to change the name of the parameter and then just copy-paste what is there to your code. You could also create another bool parameter and try that one. But you have to have everything exact, no extra spaces or capital letters, etc.
I made some changes to the code and now everything works correctly for me. Thank you very much, without your help I would not have succeeded