当前位置: 代码迷 >> 综合 >> unity c# 改变物体贴图,颜色,透明度,缩放,碰撞检测
  详细解决方案

unity c# 改变物体贴图,颜色,透明度,缩放,碰撞检测

热度:5   发布时间:2024-02-07 04:29:10.0

unity c# 改变物体贴图,颜色,透明度,缩放,碰撞检测

using UnityEngine;
using UnityEngine.UI;
using System;
using Color = UnityEngine.Color;public class Danbscontro : MonoBehaviour{//Dropdown dropdownLinetype;// Dropdown dropdownLinewidth;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(){// dropdownLinetype = GameObject.Find("Canvas/Panel/Line type").GetComponent<Dropdown>();// dropdownLinewidth= GameObject.Find("Canvas/Panel/Line width").GetComponent<Dropdown>();transform.GetComponent<InputField>().onEndEdit.AddListener(AlphaEnd_Value);//监听透明度数值transform.GetComponent<InputField>().onEndEdit.AddListener(RangeEnd_Value);//监听射程数值//anim.speed = 0.0f;}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;//Debug.Log("case0");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<MeshRenderer>().material.color = Color.white;//GOBJDanBoShuHbo.GetComponent<MeshRenderer>().material.color = Color.white;// 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(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);//return 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)//检测到碰撞体,GOBJDanBoShuHbo出现{if (other.gameObject.tag != "BiZhangBo"){GOBJDanBoShuHbo.SetActive(true);}}void OnTriggerExit(Collider collider)//障碍物消失,GOBJDanBoShuHbo消失。{GOBJDanBoShuHbo.SetActive(false);}}
-
  相关解决方案