using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class displayInfo : MonoBehavIoUr
{
public GameObject displayImage;
public Text objectNameText;
public LayerMask mask;
private void FixedUpdate()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if(Physics.Raycast(ray, out hitInfo, 200, mask))
{
if(hitInfo.collider != null)
{
Debug.DrawLine(transform.position, hitInfo.point, Color.red);
displayImage.SetActive(true);
objectNameText.text = hitInfo.collider.gameObject.name;
}
}
else
{
objectNameText.text = "";
displayImage.SetActive(false);
}
}
}
using UnityEngine;
public class Example01 : MonoBehavIoUr
{
Ray ray;
[Serializefield] private float maxdistance;//Weapon Attack Range
public LayerMask mask;
public Material highlightMat;
private void Update()
{
ray = new Ray(transform.position, transform.forward);//Create a new RAY
//RaycastHit hitInfo;//CORE STRUCT of ray original & ray direction (Store the @R_213_4045@ion about eray hit the gameObject)
//MARKER LayerMaks means we can only SHOT enemy in this layer mask
//STEP 01 Single Attack
//if(Physics.Raycast(ray, out hitInfo, maxdistance, mask, QueryTriggerInteraction.Ignore)) {
// Debug.Log(hitInfo.collider.gameObject.name);
// Debug.DrawLine(transform.position, hitInfo.point, Color.red);
//}
//else
//{
// //Debug.DrawLine(ray.origin, ray.origin + ray.direction * 100, Color.green);
// Debug.DrawRay(transform.position, transform.position + transform.forward * 100, Color.yellow);//ONLY view
//}
//STEP 02
RaycastHit[] hits;
hits = Physics.RaycastAll(ray, maxdistance);
Debug.DrawLine(transform.position, transform.position + transform.forward * 20, Color.red);
foreach(RaycastHit hit in hits)
{
hit.collider.gameObject.GetComponent<Renderer>().material = highlightMat;
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Fire : MonoBehavIoUr
{
public Material highlightMat;
private void FixedUpdate()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if(Physics.Raycast(ray, out hit, 200))
{
if(hit.collider != null)
{
hit.collider.transform.GetComponent<Renderer>().material = highlightMat;
}
}
}
}
using UnityEngine;
public class Placement : MonoBehavIoUr
{
//public LayerMask planeMask;//OPTIONAL
//public GameObject tree;
//public GameObject selectedPrefab;
//private void FixedUpdate()
//{
// //MARKER Screen Space -> Ray
// Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
// //RaycastHit hitInfo;
// if(Physics.Raycast(ray, out RaycastHit hitInfo, Mathf.Infinity, planeMask))
// {
// tree.transform.position = hitInfo.point;//The Cube will follow our Mouse
// tree.transform.rotation = Quaternion.FromToRotation(Vector3.up, hitInfo.normal);
// if (Input.GetMouseButtonDown(0))
// {
// Instantiate(tree, hitInfo.point, Quaternion.FromToRotation(Vector3.up, hitInfo.normal));
// }
// }
//}
public LayerMask planeMask;//OPTIONAL
public GameObject selectedPrefab;
private void FixedUpdate()
{
//MARKER Screen Space -> Ray
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
//RaycastHit hitInfo;
if (Physics.Raycast(ray, out RaycastHit hitInfo, Mathf.Infinity, planeMask))
{
selectedPrefab.transform.position = hitInfo.point;//The Cube will follow our Mouse
selectedPrefab.transform.rotation = Quaternion.FromToRotation(Vector3.up, hitInfo.normal);
if (Input.GetMouseButtonDown(0))
{
Instantiate(selectedPrefab, hitInfo.point, Quaternion.FromToRotation(Vector3.up, hitInfo.normal));
}
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TreeButton : MonoBehavIoUr
{
public GameObject treePrefab;
public void PressButton()
{
FindobjectOfType<Placement>().selectedPrefab = treePrefab;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class ClickMove : MonoBehavIoUr
{
private NavMeshAgent navMeshAgent;
private Ray ray;
private void Start()
{
navMeshAgent = GetComponent<NavMeshAgent>();
}
private void Update()
{
if(Input.GetMouseButtonDown(0))
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if(Physics.Raycast(ray, out hitInfo, Mathf.Infinity))
{
navMeshAgent.SetDestination(hitInfo.point);
}
}
Debug.DrawRay(Camera.main.transform.position, ray.direction * 100, Color.yellow);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。