103 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			103 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			C#
		
	
	
	
| using System.Collections;
 | |
| using System.Collections.Generic;
 | |
| using UnityEngine;
 | |
| 
 | |
| public class CheckCurrent : MonoBehaviour
 | |
| {
 | |
|     public Raycast_control raycast_Control;
 | |
|     public AudioSource audioSource;
 | |
|     public Transform 验电笔;
 | |
|     public Transform 拖拽起始位置;
 | |
|     public GameObject 使用中模型;
 | |
|     public GameObject 初始角度模型;
 | |
|     public GameObject highlighter;
 | |
|     private Vector3 startrot;
 | |
|     private Vector3 startpos;
 | |
|     public Vector3 originpos;
 | |
|     public Vector3 originrot;
 | |
|     // Start is called before the fir
 | |
|     // st frame update
 | |
|     void Start()
 | |
|     {
 | |
|         startrot = 验电笔.transform.localEulerAngles;
 | |
|         startpos = 验电笔.transform.localPosition;
 | |
| 
 | |
|         originpos = transform.localPosition;
 | |
|         originrot = transform.localEulerAngles;
 | |
|         //parent = transform.parent;
 | |
|     }
 | |
|     private void OnEnable()
 | |
|     {
 | |
|         拖拽起始位置.transform.localPosition = originpos;
 | |
|         拖拽起始位置.transform.localEulerAngles = originrot;
 | |
|     }
 | |
|     // Update is called once per frame
 | |
|     void Update()
 | |
|     {
 | |
|         if (raycast_Control.hitgo != null)
 | |
|         {
 | |
| 
 | |
| 
 | |
|             if (raycast_Control.hitgo.GetComponent<CurrentJudgment>())
 | |
|             {
 | |
|                 if (raycast_Control.hitgo.GetComponent<CurrentJudgment>().是否带电 == true)
 | |
|                 {
 | |
|                     audioSource.gameObject.SetActive(true);
 | |
|                     highlighter.SetActive(true);
 | |
|                 }
 | |
|                 初始角度模型.SetActive(false);
 | |
|                 使用中模型.SetActive(true);
 | |
|                 验电笔.transform.localEulerAngles = raycast_Control.hitgo.transform.forward;
 | |
|                 验电笔.transform.position = raycast_Control.hitInfo.point;
 | |
|                 验电笔.GetComponent<Collider>().enabled = true;
 | |
|             }
 | |
|         }
 | |
|         else
 | |
|         {
 | |
| 
 | |
|             audioSource.gameObject.SetActive(false);
 | |
|             highlighter.SetActive(false);
 | |
|             初始角度模型.SetActive(true);
 | |
|             使用中模型.SetActive(false);
 | |
|             验电笔.transform.localPosition = startpos;
 | |
|             验电笔.transform.localEulerAngles = startrot;
 | |
|             验电笔.GetComponent<Collider>().enabled = false;
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     //private void OnMouseDown()
 | |
|     //{
 | |
|     //    if (isOperation == true)
 | |
|     //    {
 | |
|     //        isOperation = false;
 | |
| 
 | |
|     //        transform.parent = parent;
 | |
|     //        transform.localPosition = originpos;
 | |
|     //        transform.localEulerAngles = originrot;
 | |
|     //        transform.Find("Cube").gameObject.SetActive(false);
 | |
|     //    }
 | |
|     //}
 | |
| 
 | |
|     /// <summary>
 | |
|     /// 正在操作
 | |
|     /// </summary>
 | |
|     //public bool isOperation = false;
 | |
|     //Transform parent;
 | |
| 
 | |
|     ///// <summary>
 | |
|     ///// 验电
 | |
|     ///// </summary>
 | |
|     ///// <param hasEle="有电"></param>
 | |
|     //public void Inspection(bool hasEle)
 | |
|     //{
 | |
|     //    isOperation = true;
 | |
| 
 | |
|     //    if (hasEle)
 | |
|     //    {
 | |
|     //        audioSource.gameObject.SetActive(true);
 | |
|     //        highlighter.constant = true;
 | |
|     //        transform.Find("Cube").gameObject.SetActive(true);
 | |
|     //    }
 | |
|     //}
 | |
| }
 |