Home > other >  Help: Unity5 written in c # Unity4 script error
Help: Unity5 written in c # Unity4 script error

Time:09-26

The younger brother beginners c # master not firm, 38 lines the following code error,
The original example is for Unity4, can directly use rigidbody2D. Velocity, but I installed Unity5, can't support the usage, seek advice,,,


 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 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;

Rigidbody2D r;

//Use this for initialization
Void the Start () {

}

//Update is called once per frame
Void the Update () {

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

Float move=Input. GetAxis (" Horizontal ");
R=GetComponentEnclosing r.v elocity=new Vector2 (move * maxSpeed, r.v elocity, y);

If ((move & gt; 0.0 f & amp; & IsFacingRight==false)
| | (move & lt; 0.0 f & amp; & IsFacingRight==true))
{
Flip ();
}

}
Void Flip ()
{
IsFacingRight=! IsFacingRight;
Vector3 playerScale=transform. LocalScale;
PlayerScale. X=playerScale. * x - 1;
The transform. LocalScale=playerScale;
}
}

CodePudding user response:

R=the transform. GetComponent
  • Related