I was following a video and in it they made a void public, but when i try it gives me a error: Screenshot - 2accf0c8f9556dc5ab1dab46dde99695 - Gyazo
Any help would be wonderful, thank you.
I was following a video and in it they made a void public, but when i try it gives me a error: Screenshot - 2accf0c8f9556dc5ab1dab46dde99695 - Gyazo
Any help would be wonderful, thank you.
It’s likely that you have a syntax error before this line, causing that error.
Please post your script here in the thread using code tags .
On a side-note, they’re called “methods” or “functions”.
“void” is just the return-type of that method, meaning it does not return any value.
See: C# - Methods for basic method concepts and syntax.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class PlayerController2D : MonoBehaviour {
public Animator animator;
Rigidbody2D rb2d;
public SpriteRenderer spriteRenderer;
float horizontalMove = 0;
[Header("Events")]
[Space]
public UnityEvent OnLandEvent;
[System.Serializable]
public class BoolEvent : UnityEvent<bool> { }
// Start is called before the first frame update
void Start()
{
animator = GetComponent<Animator>();
rb2d = GetComponent<Rigidbody2D>();
spriteRenderer = GetComponent<SpriteRenderer>();
}
// Update is called once per frame
private void FixedUpdate()
{
horizontalMove = Input.GetAxisRaw("Horizontal");
animator.SetFloat("Speed", horizontalMove);
if(Input.GetKey("d") || Input.GetKey("right"))
{
rb2d.velocity = new Vector2(2, rb2d.velocity.y);
animator.Play("Player_walk");
}
else if(Input.GetKey("a") || Input.GetKey("left"))
{
rb2d.velocity = new Vector2(-2, rb2d.velocity.y);
animator.Play("Player_walk");
}
else
{
animator.Play("Player_idle");
}
if (Input.GetKey("space"))
{
rb2d.velocity = new Vector2(rb2d.velocity.x, 3);
animator.SetBool("IsJumping", true);
}
public void OnLanding ()
{
animator.SetBool("IsJumping", false);
}
}
}
sorry it took me so long to reply, forgive me if the code sucks since ive never really coded before and this is my first movement script
The issue is that you have your method (OnLanding) inside of another method (FixedUpdate).
Moving it outside of FixedUpdate will resolve it.