51 lines
1.3 KiB
C#
51 lines
1.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
public class follow : ToolBase
|
|
{
|
|
[SerializeField] Transform game;
|
|
[SerializeField] string name;
|
|
[SerializeField] Dialogue dialogue;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
//EventTriggerListener.Get(transform.gameObject).onClick += g =>
|
|
//{
|
|
|
|
//};
|
|
}
|
|
private void Update()
|
|
{
|
|
// 鼠标左键按下
|
|
if (Input.GetMouseButtonDown(0))
|
|
{
|
|
// 从相机位置发射一条射线经过屏幕上的鼠标点击位置
|
|
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
|
|
|
// 声明一个射线碰撞信息类
|
|
RaycastHit hit;
|
|
|
|
// 进行碰撞检测
|
|
bool res = Physics.Raycast(ray, out hit) && !EventSystem.current.IsPointerOverGameObject();
|
|
|
|
if (res)
|
|
{
|
|
// 如果产生了碰撞
|
|
if (hit.transform.name.Equals(name))
|
|
{
|
|
gameObject.SetActive(false);
|
|
dialogue.gameObject.SetActive(true);
|
|
dialogue.init("你好");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// Update is called once per frame
|
|
private void FixedUpdate()
|
|
{
|
|
transform.LookAt(game);
|
|
}
|
|
}
|