Problem with player scale
Hi, I'm making my first platform game. My player (zombie) has been scaled down and made as a prefab. Everything was fine until the zombie were traded in. After adding localScale, despite the fact that the inspector is reduced in size, the player returns to the original size in game mode. I show my code: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem;
public class ZombieController : MonoBehaviour
{ [SerializeField] float walkSpeed = 7f; Vector2 moveInput; Rigidbody2D rigidbody;
void Start()
{
rigidbody = GetComponent<Rigidbody2D>();
}
void Update()
{
Walk();
FlipZombie();
}
void OnMove(InputValue value)
{
moveInput =value.Get<Vector2>();
}
void Walk()
{
Vector2 zombiegirlVelocity= new Vector2 (moveInput.x*walkSpeed,rigidbody.velocity.y);
rigidbody.velocity = zombiegirlVelocity;
}
void FlipZombie()
{
bool zombieHasHorizontalSpeed = Mathf.Abs(rigidbody.velocity.x) > Mathf.Epsilon;
if(zombieHasHorizontalSpeed)
{
transform.localScale = new Vector2 (Mathf.Sign(rigidbody.velocity.x),1f);
}
}
}
Comment