Home>
I am currently making a 3D action game with Unity and C #. I am using CharacterController to move the character, but at the start of the jump I use CharacterController's isGround = true so I don't know what to do after the jump.
(Jump is not played if anim.SetBool ("jump", false) is written in the same isGround while jumping with if (isGround) of InputButton in CharacterAnimation script)
Enable characters to jump in Unity I have read this article.
If i know how to do this, you can cut the animation halfway.
Thank you.
using System.Collections.Generic;
using UnityEngine;
public class DS4InputManager: MonoBehaviour {
protected float Rx, Ry, Lx, Ly = 0;
protected virtual void Update ()
{
InputJoysticks ();
if (Input.anyKeyDown)
{
InputButton ();
}
}
protected virtual void InputJoysticks ()
{
Rx = Input.GetAxisRaw ("Horizontal");
Ry = Input.GetAxisRaw ("Vertical");
Lx = Input.GetAxis ("LHorizontal");
Ly = Input.GetAxis ("LVertical");
Debug.Log ("Right (" + (int) Rx + "," + (int) Ry + ")");
Debug.Log ("Left (" + (int) Lx + "," + (int) Ly + ")");
}
protected virtual void InputButton ()
{
if (Input.GetButtonDown ("DS4x"))
{
Debug.Log ("Pressed x (space)");
}
if (Input.GetButtonDown ("DS4o"))
{
Debug.Log ("Pressed o (enter)");
}
// Add below if there is an addition
// if (Input.GetButtonDown (""))
// {
//}
}
}
using System.Collections.Generic;
using UnityEngine;
public class CharacterActionManager: DS4InputManager {
private CharacterController C_controller;
[SerializeField]
private float movespeed;
[SerializeField]
private float jumppower;
private CharacterAnimation C_Animation;
private Vector2 direction;
private Vector2 jumpdirection;
private void Start ()
{
C_controller = gameObject.GetComponent<CharacterController>();
C_Animation = gameObject.GetComponent<CharacterAnimation>();
}
protected override void Update ()
{
base.Update ();
GroundedCheck ();
CharacterMove ();}
protected override void InputJoysticks ()
{
base.InputJoysticks ();
Debug.Log (Lx);
if (Lx! = 0)
{
CharacterdirectionChange (Lx);
Lx = Lx * movespeed;
direction = new Vector2 (Lx, 0);
}
else
{
direction = new Vector2 (0, 0);
}
}
protected override void InputButton ()
{
base.InputButton ();
if (C_controller.isGrounded)
{
if (Input.GetButtonDown ("DS4x"))
{
jumpdirection.y = jumppower;
}
}
}
private void CharacterMove ()
{
jumpdirection.y-= jumppower * 2 * Time.deltaTime;
direction = direction + jumpdirection;
C_controller.Move (direction * Time.deltaTime);
}
private void GroundedCheck ()
{
if (! C_controller.isGrounded)
{
Debug.DrawLine (gameObject.transform.position, gameObject.transform.position-gameObject.transform.up, Color.green);
if (Physics.Linecast (gameObject.transform.position, gameObject.transform.position-gameObject.transform.up))
{
C_Animation.isGround = true;
}
else
{
C_Animation.isGround = false;
}
}
if (C_controller.isGrounded)
{
C_Animation.isGround = true;
}
}
private void CharacterdirectionChange (double direction)
{
Vector3 Angle = gameObject.transform.localEulerAngles;
if (direction == 0) return;
if (direction>0)
{
Angle.y = 90f;
}
if (direction<0){
Angle.y = -90f;
}
gameObject.transform.localEulerAngles = Angle;
}
}
using System.Collections.Generic;
using UnityEngine;
public class CharacterAnimation: DS4InputManager
{
private Animator anim;
private bool cananim;
private bool stop;
public bool isGround;
public bool landground;
private void Start ()
{
anim = gameObject.GetComponent ();
cananim = false;
stop = false;
isGround = false;
landground = true;
}
protected override void InputJoysticks ()
{
base.InputJoysticks ();
if (Lx! = 0)
{
if (! anim.GetCurrentAnimatorStateInfo (0) .IsName ("jump"))
{
anim.SetBool ("run", true);
}
}
else
{
anim.SetBool ("run", false);
}
}
protected override void InputButton ()
{
base.InputButton ();
if (! stop)
{
if (Input.GetButtonDown ("DS4o"))
{
anim.SetTrigger ("skill" + 1);
Debug.Log ("skill" + 1);
}
}
if (isGround)
{
if (Input.GetButtonDown ("DS4x"))
{
anim.SetBool ("jump", true);
Debug.Log ("JUMP");
}
anim.SetBool ("jump", false);
}
}
}
-
Answer # 1
Related articles
- c # - jumping when using rigidbody2dvelocity
- c # - i set an excel value using npoi, but it is not reflected in the reference
- c # - i want to run unity: transformtranslate using rigidbody
- c # - [wpf] how to play an animation only when the code-behind conditions are met
- c # - blackjack (creating a deck using a mold you made)
- c # - large number of same errors (using vuforia)
- c # - how to move an object straight using unity3d dotween
- i want to get the characters in a word file in c # without using visual studio
- how to avoid using console for interprocess communication in c # wcf ipc?
- c # - i want to make a server-side gui application using websocket-sharp
- c # syntax when using azure cognitive service
- i want to download a file from a bucket using a uri in c # with a format starting with s3: //
- c # - play sound effects using unity is trigger
- c # - i want to know the progress by using the progress bar etc when executing sql
- c # - i can't bind using relativesource when i put contextmenu in between
- not enough middle parenthesis c #
- c # - i want to load scores on my device using playerprefs
- c # - i don't understand the stairs calculation using bit operation in a millionaire
- c # - deactivate text after animation
- c # - about error when using social connector in unity
Related questions
- c # - i want to specify a different url from the script side for the video player component of unity
- c # - gyro sensor does not respond when building on android device
- c # - i added the arjs plugin to unity, but webar does not appear in the browser
- c # - i want to replace a file with the same name in asset
- c # - touch judgment of unity object
- c # - i want to create a webar in unity
- c # - play sound effects using unity is trigger
- c # - build from xcode to ios doesn't work ("unitydefaultviewcontroller should be used only if unity is set" is displa
- i want to use addforce to move forward when i press the q key in a c # script
- i want to limit input alternately left and right unity c #
The flag can be set to true in update, and the flag can be set to false during jump animation.