i can't disable a script while playing
i simply can't disable my script while playing, i used everything but it's not working i can't even disable it manually
full script:
using UnityEngine;
public class PlayerMovement : MonoBehaviour { public float moveSpeed; public float climbSpeed; public CapsuleCollider2D playerCollider; public float jumpForce;
private bool isJumping; public bool isGrounded;
public bool isClimbing; public Transform groundCheck; public float groundCheckRadius; public LayerMask collisionLayers;
public Rigidbody2D rb; public Animator animator; public SpriteRenderer spriteRenderer;
private Vector3 velocity = Vector3.zero; private float horizontalMovement; private float verticalMovement;
public static PlayerMovement instance; public void Awake() { if(instance != null) { Debug.Log("Il y a plus d'une instance de PlayerMovement dans la scène "); return; } instance = this; }
void Update() {
horizontalMovement = Input.GetAxis("Horizontal") * moveSpeed * Time.fixedDeltaTime;
verticalMovement = Input.GetAxis("Vertical") * climbSpeed * Time.fixedDeltaTime;
if (Input.GetButtonDown("Jump") && isGrounded && !isClimbing )
{
isJumping = true;
}
Flip(rb.velocity.x);
float characterVelocity = Mathf.Abs(rb.velocity.x);
animator.SetFloat("Speed", characterVelocity);
animator.SetBool("isClimbing", isClimbing);
}
void FixedUpdate() {
isGrounded = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, collisionLayers);
MovePlayer(horizontalMovement, verticalMovement);
}
void MovePlayer(float _horizontalMovement, float _verticalMovement) { if (!isClimbing) { Vector3 targetVelocity = new Vector2(_horizontalMovement, rb.velocity.y); rb.velocity = Vector3.SmoothDamp(rb.velocity, targetVelocity, ref velocity, .05f);
if(isJumping)
{
rb.AddForce(new Vector2(0f, jumpForce));
isJumping = false;
}
}
else
{
// déplacement vcertical
Vector3 targetVelocity = new Vector2(0, _verticalMovement);
rb.velocity = Vector3.SmoothDamp(rb.velocity, targetVelocity, ref velocity, .05f);
}
}
void Flip(float _velocity) { if (_velocity > 0.1f) { spriteRenderer.flipX = false; } else if (_velocity < -0.1f) { spriteRenderer.flipX = true; } } private void OnDrawGizmos() { Gizmos.color = Color.red; Gizmos.DrawWireSphere(groundCheck.position, groundCheckRadius); }
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613004813im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Hey all I am working on a 3D maze game. I would like to know how i could start and end the levels . 1 Answer
Do you need to have specific script types for different mobile platforms? 1 Answer
why do i keep getting compiler errors even though my script has no errors? 2 Answers
Picking up collectables in a correct (custom set) order to open gates? 0 Answers
Auto switch to legacy shader 0 Answers