Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class raycast : MonoBehaviour {
- private Terrain terrain;
- // Update is called once per frame
- void Update() {
- TreeInstance clickedTree=new TreeInstance();
- if (Input.GetMouseButtonDown(0))
- {
- RaycastHit hit;
- TreeInstance aktStrom;
- TreeInstance[] stromy = Terrain.activeTerrains[1].terrainData.treeInstances;
- if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
- {
- float minDistance = float.MaxValue;
- if (hit.collider.tag == "Enviroment") {
- print(stromy.Length);
- for (int i = 0; i < stromy.Length; i++)
- {
- aktStrom = stromy[i];
- float dist = Vector3.Distance(hit.point, aktStrom.position);
- if (dist < minDistance)
- {
- print(dist + " " + minDistance + " " + aktStrom.position);
- clickedTree = aktStrom;
- minDistance = dist;
- }
- Main.display = true;
- Main.text = clickedTree.prototypeIndex.ToString();
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement