#Dead player moves
1 messages · Page 1 of 1 (latest)
you have your HeartSystem
reference that from the player
then you can check if dead == true
and then dont run your input code
can you write the code for me cuz idk how to do it ,i just took the script from someone
thats a no
i can help you with the steps you are stuck on but you have to write the code
}
void Update(){
if (dead == true ){
// Set Dead Code
pm.enabled = false;
Skull.SetActive(true);
animator.SetBool("Death", true);
}else{
Skull.SetActive(false);
pm.enabled = true;
animator.SetBool("Death", false);
}
}```
first step
make a public variable of type HeartSystem in your PlayerMovement2D class
like this public PlayerMovement2D pm;??
looks good
and step two is... :>
mmm i see that disable the PlayerMovement2D component when your player dies
can you check that that happens when you die?
i did not see that code at first it should accomplish what you are trying to do
it happens when i disable the playermovement script
this is the playermovement script
give me a second
i look into how we can fix that
tyt
where do i put it ?
it set the velocity (the movement speed) of the player to 0 if the player movemnt is disabled
PlayerMovement2D
i hope that the CharacterController2D not prevents this
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerMovement2D : MonoBehaviour
{
[SerializeField] private LadderMovement ladderMovementScript;
public CharacterController2D Controller;
private Rigidbody2D rb;
public Animator animator;
public float runSpeed = 40f;
float horizontalMove = 0f;
bool jump = false;
bool crouch = false;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
animator.SetFloat("Speed", Mathf.Abs(horizontalMove));
if (Input.GetButtonDown("Jump")){
jump = true;
animator.SetBool("IsJumping", true);
}
if (Input.GetButtonDown("Crouch")){
crouch = true;
}
else if (Input.GetButtonUp("Crouch")){
crouch = false;
}
}
public void Onlanding (){
animator.SetBool("IsJumping", false);
}
void FixedUpdate()
{
// Move our character
Controller.Move(horizontalMove * Time.fixedDeltaTime, crouch, jump);
jump = false;
}
void OnDisable()
{
rb.velocity = Vector2.zero;
}
}
like this ?
yes
ah ok
is the Rigidbody2D component on the same gamobject as the PlayerMovement2D ?
yes
ok lets change
rb.velocity = Vector2.zero;
to
gameObject.GetComponent<Rigidbody2D >().velocity = Vector2.zero;
It Works !!!!!
nice
Thanks a lot i've been trying to fix it for like 6 hours and you solve it in minutes :>