Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my script:
using UnityEngine;

public class PlayerController : MonoBehaviour {

public Animator animator;
void Update () {
if (Input.GetKeyDown(KeyCode.J)) {
animator.SetTrigger("sword in");
}
}

public class Identifier {
}
public Update () {
if (Input.GetKeyDown(KeyCode.k)) {
animator.SetTrigger("sword out");
}
}

}


What I have tried:

i tried to change the whole script but it dont work
Posted
Updated 27-Feb-21 11:20am

You're probably missing a void return type.
public class Identifier {
}
public somethingMissingHere Update () {
if (Input.GetKeyDown(KeyCode.k)) {
animator.SetTrigger("sword out");
}
}
 
Share this answer
 
Comments
Member 15085691 28-Feb-21 6:28am    
thank you! but what do i need to put i the plane off somethingMissingHere
Dave Kreskowiak 28-Feb-21 11:07am    
I don't know what your code is supposed to be doing or if it's supposed to be returning anything.

So, looking at what you posted, it doesn't appear as though it intends to return anything, so your answer would be void.
To add to what Dave has - correctly - said: the only time you can declare a method without a return type is when the method name is the same as the class name: when it is a constructor, and that's because the return type of a constructor can only ever be an instance of the class type.

A constructor is a special method that is never called directly - it can only be called when you instantiate a class by using the new keyword:
C#
public class MyClass
   {
   public MyClass() 
      {
      ...
      }
   }
...
MyClass x = new MyClass();
The only exception to that is when the constructor is static - then it is never called directly, but called by the system at some point prior to the first usage of the class.

If you omit the return type to a "normal" method, the system assumes you wanted to create a constructor, but then complains because it can't work out when to call it.
 
Share this answer
 
Comments
Member 15085691 28-Feb-21 6:29am    
thank you!
OriginalGriff 28-Feb-21 6:51am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900