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