using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class mouse : MonoBehaviour
{
public Color oldColor;
public bool isPlay=false;
// Start is called before the first frame update
void Start()
{
oldColor = GetComponent<Renderer>().material.color;//渲染组件的材质中的颜色
}
// Update is called once per frame
void Update()
{
}
//鼠标选中时调用该函数;
void OnMouseOver() {
GetComponent<Renderer>().material.color = Color.red;
transform.Rotate(0, 180 * Time.deltaTime, 0);
}
//鼠标移开时调用该函数;
void OnMouseExit() {
GetComponent<Renderer>().material.color = oldColor;
}
//鼠标单击时调用该函数;
void OnMouseDown() {
if (isPlay) {
GetComponent<AudioSource>().Stop();
isPlay = false;
}
else {
GetComponent<AudioSource>().Play();
isPlay =true;
}
}
}
- 改变纹理
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class inventory : MonoBehaviour
{
public static int charge = 0;
public Texture2D[] imgs;
public Texture2D[] imgs_box;
public RawImage img;
public Renderer renderer;
public AudioClip audioClip;
private AudioSource audioPlayer;
// Start is called before the first frame update
void Start()
{
audioPlayer = GetComponent<AudioSource>();
}
// Update is called once per frame
void Update()
{
}
void cellpickup() {
charge++;
audioPlayer.clip = audioClip;
audioPlayer.Play();
img.texture = imgs[charge];
renderer.material.mainTexture = imgs_box[charge];
}
}