Unity3D 鼠标点击切换图片
佩琪和乔治切换
创建ChangeFace脚本,挂在peiqi3上
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChangeFace : MonoBehaviour
{
public Sprite sprite1;
public Sprite sprite2;
private int index = 0;
// Start is called before the first frame update
void Start()
{
Debug.Log("start ... ");
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0)) {
DoChange();
}
}
void DoChange() {
SpriteRenderer renderer = GetComponent();
if (index == 0) {
index = 1;
renderer.sprite = this.sprite1;
} else {
index = 0;
renderer.sprite = this.sprite2;
}
}
}



