I have an assets file under the name of play-button with texture type=sprite2D
and Sprite Mode = Multiple
, it contains 2 different frames: play-button0
and play-button1
i have attached a c# script file for this asset with the following code:
using UnityEngine;
using System.Collections;
public class Play_btn : MonoBehaviour {
SpriteRenderer spriteRenderer;
Sprite s1;
Sprite s2;
// Use this for initialization
void Start () {
spriteRenderer = GetComponent<SpriteRenderer>();
if (spriteRenderer.sprite == null)
spriteRenderer.sprite = s1;
}
void OnMouseDown() {
Application.LoadLevel("Levels");
}
void OnMouseEnter() {
spriteRenderer.sprite = s2;
}
void OnMouseExit() {
//spriteRenderer.sprite = sprite1;
}
// Update is called once per frame
void Update () {
}
}
As you can see i am trying to change the frame onMouseEnter
and OnMouseExit
but when the mouseEnter
the play button a null reference error is occurring and a blank object is displaying on the screen, can anyone help me in this problem?