Home c# How to make control for a 2D character in Unity on a...

How to make control for a 2D character in Unity on a PC, without double jump and with a player turn in different directions

Author

Date

Category

How to make control for a 2D character in unity on a PC, without a double jump and with a player turn in different directions


Answer 1, Authority 100%

How to configure the script shown in video

using system.collections;
Using System.Collections.Genic;
using System.Runtime.comPilerservices;
using unityengine;
Public Class PF: Monobehaviour
{
  RigidBody2D RB;
  Public Float Speed;
  Public Float Jumpheight;
  Public Transform GroundCheck;
  BOOL ISGROUNED;
  Animator Anim;
  Void Start ()
  {
    rb = getComponent & lt; rigidbody2d & gt; ();
  }
  Void Update ()
  {
    Flip ();
    Checkground ();
    rb.Velocity = new vector2 (input.getaxis ("horizontal") * Speed, rb.Velocity.y);
    if (input.GetKeyDown (keycode.space) & amp; & amp; isgrounded)
      RB.AddForce (transform.up * jumpheight, forecemode2d.impulse);
  }
  Void Flip ()
  {
    if (input.getaxis ("horizontal") & gt; 0)
    transform.localrotation = quaternion.euler (0, 0, 0);
    if (Input.Getaxis ("Horizontal") & lt; 0)
    transform.localrotation = quaternion.euler (0, 180, 0);
  }
  Void Checkground ()
  {
    Collider2D [] Colliders = Physics2d.Overlapcircleall (GroundCheck.position, 1);
    isgrounded = colliders.length & gt; 1;
  }
}

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions