Home > other >  Consult! Jump code error
Consult! Jump code error

Time:09-16

For help!
The original case is based on Unity4, what I use is Unity5
Line # 70 and # 89 error, the reason is jumpMaterial is not defined, to be honest I don't understand why this code to this design, ask tall person to give directions



 using System. The Collections; 
Using System. Collections. Generic;
Using UnityEngine;

Public class PlayController: MonoBehaviour {
[HideInInspector]
Public bool isFacingRight=true;
[HideInInspector]
Public bool isJumping=false;
[HideInInspector]
Public bool isDoubleJumping=false;
[HideInInspector]
Public bool isGrounded=false;

Public float jumpForce=650.0 f;
Public float maxSpeed=7.0 f;

Public Transform groundCheck;
Public LayerMask groundLayers;

Private float groundCheckRadius=0.2 f;
Private Animator anim.

Void awake () {
Anim=GetComponent (a);
}
////Use this for initialization
//void the Start () {
//}

//Update is called once per frame
Void the Update () {
If (Input. GetButtonDown (" Jump "))
{
If (isGrounded==true) {
This. GetComponentThis. GetComponentThis. Anim. SetTrigger (" Jump ");
{} else if (isDoubleJumping==false)
IsDoubleJumping=true;
This. GetComponentThis. GetComponent}


}
}

Private void FixedUpdate ()
{
IsGrounded=Physics2D. OverlapCircle
(groundCheck. Position, groundCheckRadius groundLayers);

PhysicsMaterial2D material.=this gameObject. GetComponent
If (isGrounded==true)
{
IsDoubleJumping=false;
}
If (isGrounded==true & amp; & Material==this. JumpMaterial) {
CircleCollider2D collision.=this gameObject. GetComponentA collision. SharedMaterial=null;
A collision. Enabled=false;
A collision. Enabled=true;
}
Else if (isGrounded==false& & Enclosing gameObject. GetComponent{
CircleCollider2D collision.=this gameObject. GetComponentA collision. SharedMaterial=this. JumpMaterial;
A collision. Enabled=false;
A collision. Enabled=true;
}


Float move=Input. GetAxis (" Horizontal ");
Try
{
This. GetComponentThis. Anim. SetFloat (" Speed ", Mathf. Abs (move));
If ((move & gt; 0.0 f & amp; & IsFacingRight==false) | | (move & lt; 0.0 f & amp; & IsFacingRight==true))
{
Flip ();
}
}
The catch (UnityException error) {
The Debug. LogError (error. The toString ());
}
}
Void Flip ()
{
IsFacingRight=! IsFacingRight;
Vector3 playerScale=transform. LocalScale;
PlayerScale. X=playerScale. * x - 1;
The transform. LocalScale=playerScale;
}
}

CodePudding user response:

You can't define jumpmaterial, must be an error
  • Related