Answer the question
In order to leave comments, you need to log in
When I press the go left button do textures disappear?
Bug when walking, when I click on the button to go to the left, the textures of all sprites disappear, what should I do? UNITY 2D
here is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class cucumbercontrol : MonoBehaviour
{
public float speed;
public float normalSpeed;
public float jumpForce;
private float moveInput;
private Rigidbody2D rb;
private bool facingRight = true;
private bool isGrounded;
public Transform feetPos;
public float checkRadius;
public LayerMask whatIsGround;
private void Start()
{
speed = 0f;
rb = GetComponent<Rigidbody2D>();
}
private void FixedUpdate()
{
rb.velocity = new Vector2(speed, rb.velocity.y);
if (facingRight == false && moveInput > 0)
{
Flip();
}
else if (facingRight == true && moveInput < 0)
{
Flip();
}
}
private void Update()
{
isGrounded = Physics2D.OverlapCircle(feetPos.position, checkRadius, whatIsGround);
if(isGrounded == true && Input.GetKeyDown(KeyCode.Space))
{
rb.velocity = Vector2.up * jumpForce;
}
}
public void OnJumpButtonDown()
{
if (isGrounded == true)
{
rb.velocity = Vector2.up * jumpForce;
}
}
public void OnLeftButtonDown()
{
if (speed >= 0f)
{
speed = -normalSpeed;
transform.eulerAngles = new Vector3(0, 180, 0);
}
}
public void OnRightButtonDown()
{
if (speed <= 0f)
{
speed = normalSpeed;
transform.eulerAngles = new Vector3(0, 360, 0);
}
}
void Flip()
{
facingRight = !facingRight;
Vector3 Scaler = transform.localScale;
Scaler.x *= -1;
transform.localScale = Scaler;
}
public void OnButtonUp()
{
speed = 0f;
}
}
Answer the question
In order to leave comments, you need to log in
There is a possibility that you are leaving behind the textures. Since you are using 2D physics, but when you press a key, you are using Vector3 for 3D graphics.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question