I need help switching sprites when I press A and D

  Kiến thức lập trình

I am trying to make a script where the sprite changes depending on what button you press, right now I am only doing A and D, left and right. I cant get anything to work, I have tried everything I can,

using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;

public class Sprites
{
    public string gameObject;
    public SpriteRenderer spriteRenderer;
    public Sprite SpriteRight;
    public Sprite SpriteLeft;

    void ChangeSprite()
    {
        if (Input.GetKeyDown(KeyCode.D))
        {
            gameObject.GetComponent<SpriteRenderer>().sprite = SpriteRight;
        }
    }

}```


I have tried many forums and different approaches, and nothing ever ends up working, im new to unity as well so please bare with my idiocy.

New contributor

goatgamerten is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT