You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
using System.Collections ;
using System.Collections.Generic ;
using TMPro ;
using UnityEngine ;
using UnityEngine.UI ;
using UnityEngine.Video ;
public class Caster : MonoBehaviour
{
public int bag ;
public TextMeshProUGUI text ;
public bool play = false ;
// Start is called before the first frame update
void Start ( )
{
bag = 0 ;
}
// Update is called once per frame
void Update ( )
{
if ( Input . GetMouseButtonDown ( 0 ) )
{
Ray ray = Camera . main . ScreenPointToRay ( Input . mousePosition ) ; // 创建一个射线源,射线发射的位置
RaycastHit hitInfo ; // 射线打中的目标,当前为空
// 发射射线进行射线检测
// 参数一:射线源
// 参数二: out关键字返回打中的对象
if ( Physics . Raycast ( ray , out hitInfo ) )
{
// 调试信息:绘制一条线,连接摄像机坐标和打中物体的坐标
Debug . DrawLine ( Camera . main . transform . position , hitInfo . point ) ;
// 判断打中的物体, 也可以用name等其他属性进行判断
if ( hitInfo . transform . tag = = "item" ) {
bag + + ; // 背包数量加1
text . text = "items:" + bag . ToString ( ) ; // 显示在UI上我们的背包数量
hitInfo . transform . GetComponent < cube > ( ) . clicked = true ;
hitInfo . transform . GetComponent < MeshRenderer > ( ) . enabled = false ;
//hitInfo.transform.gameObject.SetActive(false); // 把拾取到的道具销毁
//hitInfo.transform.GetComponentInChildren<ParticleSystem>().Play();
}
if ( hitInfo . transform . tag = = "video" )
{
play = ! play ;
if ( play )
{
hitInfo . transform . GetComponent < VideoPlayer > ( ) . Play ( ) ;
}
else
{
hitInfo . transform . GetComponent < VideoPlayer > ( ) . Pause ( ) ;
}
}
}
}
}
}