,…
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
public class Player : MonoBehaviour
{ /float controlPlayer = Input.GetAxis(“Horizontal”);/
//config
[SerializeField] float runSpeed = 5f;
[SerializeField] float jumpSpeed = 5f;
[SerializeField] float climbSpeed = 5f;
//State
bool isAlive = true;
Rigidbody2D myRigidBody;
Animator myAnimator;
Collider2D myCollider2D;
void Start()
{
myRigidBody = GetComponent<Rigidbody2D>();
myAnimator = GetComponent<Animator>();
myCollider2D = GetComponent<Collider2D>();
}
// Update is called once per frame
void Update()
{
Run();
FlipSprite();
Jump();
ClimbLadder();
}
private void Run()
{
float controlThrow = CrossPlatformInputManager.GetAxis("Horizontal"); // value is betweeen -1 to +1
Vector2 playerVelocity = new Vector2(controlThrow * runSpeed, myRigidBody.velocity.y);
myRigidBody.velocity = playerVelocity;
//makes idle work by playerHasHorizontalSpeed if there is any or not makes the true or false values
bool playerHasHorizontalSpeed = Mathf.Abs(myRigidBody.velocity.x) > Mathf.Epsilon;
myAnimator.SetBool(“Running”, playerHasHorizontalSpeed);
}
private void ClimbLadder()
{
if (!myCollider2D.IsTouchingLayers(LayerMask.GetMask("Climbing"))) { return; }
float controlThrow = CrossPlatformInputManager.GetAxis("Vertical");
Vector2 climbVelocity = new Vector2(myRigidBody.velocity.x, controlThrow * climbSpeed);
myRigidBody.velocity = climbVelocity;
}
private void Jump()
{
//if the condition is not met then don't let the player jump
if(!myCollider2D.IsTouchingLayers(LayerMask.GetMask("Ground")))
{ return; }
if (CrossPlatformInputManager.GetButtonDown("Jump"))
{
Vector2 jumpVelocityToAdd = new Vector2(0f, jumpSpeed);
myRigidBody.velocity += jumpVelocityToAdd;
}
//if player is moving horizontally reverse the current scaling of the X asis
}
private void FlipSprite()
{
bool playerHasHorizontalSpeed = Mathf.Abs(myRigidBody.velocity.x) > Mathf.Epsilon;
if (playerHasHorizontalSpeed)
{
transform.localScale = new Vector2(Mathf.Sign(myRigidBody.velocity.x), 1f);
}
}
}
…,
I have the climbing ladder on Climbing sorting layer & layer (user 9). I think it’s because in 2017.3 the grid options are less then in 2020 so I have an idea. Can anyone assist or just tell me why my player is ignoring the ladder? Yes the ladder/climbing is trigger.