unity c# 改变物体贴图,颜色,透明度,缩放,碰撞检测
using UnityEngine;
using UnityEngine.UI;
using System;
using Color = UnityEngine.Color;public class Danbscontro : MonoBehaviour{public Texture linetype1;public Texture linetype2;public Texture linetype3;public Texture linetype4;public Texture linetype5;public GameObject GOBJDanBoShu;public GameObject GOBJDanBoShuHbo;float f_alpha=1;float f_range;void Start(){transform.GetComponent<InputField>().onEndEdit.AddListener(AlphaEnd_Value);transform.GetComponent<InputField>().onEndEdit.AddListener(RangeEnd_Value);}private void Update(){anim.speed = 1f;}public void GetTypeValue(int i){switch (i){case 0:GOBJDanBoShu.GetComponent<Renderer>().material.mainTexture = linetype1;GOBJDanBoShuHbo.GetComponent<Renderer>().material.mainTexture = linetype1;break;case 1:GOBJDanBoShu.GetComponent<Renderer>().material.mainTexture = linetype2;GOBJDanBoShuHbo.GetComponent<Renderer>().material.mainTexture = linetype2;break;case 2:GOBJDanBoShu.GetComponent<Renderer>().material.mainTexture = linetype3;GOBJDanBoShuHbo.GetComponent<Renderer>().material.mainTexture = linetype3;break;case 3:GOBJDanBoShu.GetComponent<Renderer>().material.mainTexture = linetype4;GOBJDanBoShuHbo.GetComponent<Renderer>().material.mainTexture = linetype4;break;case 4:GOBJDanBoShu.GetComponent<Renderer>().material.mainTexture = linetype5;GOBJDanBoShuHbo.GetComponent<Renderer>().material.mainTexture = linetype5;break;}}public void GetWidthValue(int i){Vector3 DanBSscale1 = GOBJDanBoShu.transform.localScale;switch (i){case 0:DanBSscale1.x = DanBSscale1.y;DanBSscale1.z = DanBSscale1.y;break;case 1:DanBSscale1.x = 2 * DanBSscale1.y;DanBSscale1.z = 2 * DanBSscale1.y;break;case 2:DanBSscale1.x = 3*DanBSscale1.y;DanBSscale1.z = 3*DanBSscale1.y;break;}GOBJDanBoShu.transform.localScale = DanBSscale1;}public void GetColourValue(int i){ switch (i){case 0://红GOBJDanBoShu.GetComponent<Renderer>().material.color = new Color(255, 255, 255, f_alpha);GOBJDanBoShuHbo.GetComponent<MeshRenderer>().material.color = new Color(255, 255, 255, f_alpha);break;case 1:GOBJDanBoShu.GetComponent<MeshRenderer>().material.color = new Color(0, 255, 0, f_alpha);GOBJDanBoShuHbo.GetComponent<MeshRenderer>().material.color = new Color(0, 255, 0, f_alpha);break;case 2:GOBJDanBoShu.GetComponent<MeshRenderer>().material.color = new Color(255, 0, 0, f_alpha);GOBJDanBoShuHbo.GetComponent<MeshRenderer>().material.color = new Color(255, 0, 0, f_alpha);break;case 3:GOBJDanBoShu.GetComponent<MeshRenderer>().material.color = new Color(255, 255, 0, f_alpha);GOBJDanBoShuHbo.GetComponent<MeshRenderer>().material.color = new Color(255, 255, 0, f_alpha);break;case 4:GOBJDanBoShu.GetComponent<MeshRenderer>().material.color = new Color(0, 0, 255, f_alpha);GOBJDanBoShuHbo.GetComponent<MeshRenderer>().material.color = new Color(0, 0, 255, f_alpha);break;case 5:GOBJDanBoShu.GetComponent<MeshRenderer>().material.color = new Color(0, 0, 0, f_alpha);GOBJDanBoShuHbo.GetComponent<MeshRenderer>().material.color = new Color(0, 0, 0, f_alpha);break;case 6:GOBJDanBoShu.GetComponent<MeshRenderer>().material.color = new Color(40, 40, 40, f_alpha);GOBJDanBoShuHbo.GetComponent<MeshRenderer>().material.color = new Color(40, 40, 40, f_alpha);break;}}public void AlphaEnd_Value(string inp){f_alpha = Convert.ToSingle(inp);var r = GOBJDanBoShu.GetComponent<Renderer>().material.color.r;var g = GOBJDanBoShu.GetComponent<Renderer>().material.color.g;var b = GOBJDanBoShu.GetComponent<Renderer>().material.color.b;GOBJDanBoShu.GetComponent<Renderer>().material.color = new Color(r, g, b, f_alpha);GOBJDanBoShuHbo.GetComponent<Renderer>().material.color = new Color(r, g, b, f_alpha);}public void RangeEnd_Value(string inp){ f_range = Convert.ToSingle(inp);Vector3 ObjScale = GOBJDanBoShu.transform.localScale;ObjScale.x = f_range ;ObjScale.y = f_range ;ObjScale.z = f_range ;GOBJDanBoShu.transform.localScale = ObjScale;}void OnTriggerStay(Collider other){if (other.gameObject.tag != "BiZhangBo"){GOBJDanBoShuHbo.SetActive(true);}}void OnTriggerExit(Collider collider){GOBJDanBoShuHbo.SetActive(false);}}
-