unity 2d movement and animation
OK Dude I had this problem and found a good yt video I hope this helps whoever comes past it and yh here
link: https://www.youtube.com/watch?v=rycsXRO6rpI
unity 2d movement and animation
OK Dude I had this problem and found a good yt video I hope this helps whoever comes past it and yh here
link: https://www.youtube.com/watch?v=rycsXRO6rpI
2d movement unity
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
//for A&D / Right&Left Arrow And Jump Movement
//for Adding W&S Movement, Remove The Slashes Below And Add Slashes
//To Jump Movement Only Also In RigidBody2D Remove Gravity For It
public Rigidbody2D rb;
private bool IsGrounded = true;
private float MoveX;
//private float MoveY;
private bool DoDeath = true;
public GameObject DeathScreen;
public GameObject LevelCompleteScreen;
void Start()
{
DeathScreen.gameObject.SetActive(false);
LevelCompleteScreen.gameObject.SetActive(false);
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void FixedUpdate()
{
Debug.Log(IsGrounded);
if(Input.GetButtonDown("Jump") && IsGrounded)
{
//Remove These 2 Lines Below For W&s Movement Only
rb.AddForce(new Vector2(0,500));
IsGrounded = false;
}
MoveX = Input.GetAxisRaw("Horizontal");
Remove The Slashes For W&S Movement Only
//MoveY = Input.GetAxisRaw("Vertical");
//Slash The Below Line Out For W&S Movement Only
rb.AddForce(new Vector2(MoveX * 20, 0));
//Remove The Slashes For W&S Movement Only
//rb.velocity = (new Vector2(MoveX * 20, MoveY * 20));
}
public void OnTriggerEnter2D(Collider2D ob)
{
if(DoDeath)
{
if(ob.name == "DeathTrigger")
{
DeathScreen.gameObject.SetActive(true);
}
if(ob.name == "Finish")
{
LevelCompleteScreen.gameObject.SetActive(true);
DoDeath = false;
}
}
}
public void OnCollisionEnter2D()
{
IsGrounded = true;
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us