[英]Can you help me with this jumping animation code I am having trouble with it
I'm trying to make a jump animation and I have one error thats being too well... Broad this is the error code我正在尝试跳转 animation 并且我有一个错误,那就太好了...广泛这是错误代码
"Assets\Character2DController.cs(64,9): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement" “Assets\Character2DController.cs(64,9): error CS0201: 只有赋值、调用、递增、递减、等待和新的object表达式可以作为语句使用”
And here is the code I have (it's all on one page):这是我拥有的代码(都在一页上):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Character2DController : MonoBehaviour
{
public float MovementSpeed = 1;
public float JumpForce = 1;
private Rigidbody2D _rigidbody;
private Animator anim;
private bool Grounded;
// Start is called before the first frame update
private void Start()
{
anim = GetComponent<Animator>();
_rigidbody = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
private void Update()
{
float movement = Input.GetAxis("Horizontal");
transform.position += new Vector3(movement,0,0) * Time.deltaTime * MovementSpeed;
if(Input.GetKey(KeyCode.Space) && Grounded)
Player_jump();
//this is animation do not grab if reusing this code (whats below this)
if(movement == 1)
transform.localScale = Vector3.one;
else if (movement == -1)
transform.localScale = new Vector3(-1, 1, 1);
anim.SetBool ("Grounded", Grounded);
if (movement == 0) {
anim.SetBool("IsWalking", false);
}
if (movement == 1){
anim.SetBool("IsWalking", true);
}
if (movement == -1){
anim.SetBool("IsWalking", true);
}
}
private void Player_jump()
{
_rigidbody.velocity = new Vector2(_rigidbody.velocity.x, MovementSpeed);
Grounded = false;
}
private void OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.tag == "Ground")
Grounded == true;
}
}
Line 64 is here:第 64 行在这里:
private void OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.tag == "Ground")
Grounded == true; /* <--- line 64 */
}
The problem is that you're using two =
symbols, which makes this an equality check, rather than what you mean to do, which is assigning true to Grounded with one =
.问题是您使用了两个=
符号,这使其成为相等性检查,而不是您的意思,即使用一个=
将 true 分配给 Grounded。 Change to Grounded = true;
更改为Grounded = true;
and it should fix the error.它应该修复错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.