Why I am getting this error when changing the Deathblow variable as shown in screenshot??
Her is my code:-
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMovement : MonoBehaviour
{
Vector2 moveInput;
bool isPlayerRunning;
bool isPlayerClimbing;
bool isTouchingLayers;
bool isPlayerAlive = true;
Rigidbody2D playerRigidbody;
Animator playerAnimator;
CapsuleCollider2D playerBodyCollider;
BoxCollider2D playerFeetCollider;
// SpriteRenderer playerSpriteRenderer;
[SerializeField] float playerMoveSpeed = 2f;
[SerializeField] float playerJumpSpeed = 5f;
[SerializeField] float playerClimbSpeed = 3f;
[SerializeField] Vector2 deathblow = new Vector2(4f, 4f);
// [SerializeField] Color32 playerDeathColor;
float playerStartingGravity;
void Start()
{
playerRigidbody = GetComponent<Rigidbody2D>();
playerAnimator = GetComponent<Animator>();
playerBodyCollider = GetComponent<CapsuleCollider2D>();
playerFeetCollider = GetComponent<BoxCollider2D>();
// playerSpriteRenderer = GetComponent<SpriteRenderer>();
playerStartingGravity = playerRigidbody.gravityScale;
}
void Update()
{
isPlayerRunning = Mathf.Abs(moveInput.x) > Mathf.Epsilon;
isPlayerClimbing = Mathf.Abs(moveInput.y) > Mathf.Epsilon;
if(!isPlayerAlive) { return; }
FlipPlayer();
Run();
ClimbLadder();
Die();
}
void OnMove(InputValue value)
{
moveInput = value.Get<Vector2>();
Debug.Log("Player moving...");
}
void OnJump(InputValue value)
{
if(isPlayerAlive)
{
if(value.isPressed && playerFeetCollider.IsTouchingLayers(LayerMask.GetMask("Ground")))
{
playerRigidbody.velocity += new Vector2(0f, playerJumpSpeed);
}
}
}
void FlipPlayer()
{
if(isPlayerRunning)
{
transform.localScale = new Vector2(Mathf.Sign(moveInput.x), 1f);
}
}
void Run()
{
playerAnimator.SetBool("isRunning", isPlayerRunning);
Vector2 playerMoveVelocity = new Vector2(moveInput.x * playerMoveSpeed, playerRigidbody.velocity.y);
playerRigidbody.velocity = playerMoveVelocity;
}
void ClimbLadder()
{
if(playerBodyCollider.IsTouchingLayers(LayerMask.GetMask("Climbs")))
{
playerAnimator.SetBool("isClimbing", isPlayerClimbing);
playerRigidbody.gravityScale = 0;
Vector2 playerClimbVelocity = new Vector2(playerRigidbody.velocity.x, moveInput.y * playerClimbSpeed);
playerRigidbody.velocity = playerClimbVelocity;
}
else
{
playerAnimator.SetBool("isClimbing", false);
playerRigidbody.gravityScale = playerStartingGravity;
}
}
void Die()
{
if(playerBodyCollider.IsTouchingLayers(LayerMask.GetMask("Enemies", "Hazards")))
{
isPlayerAlive = false;
playerAnimator.SetTrigger("Dying");
playerRigidbody.velocity = deathblow;
// playerSpriteRenderer.color = playerDeathColor;
}
}
}