Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class raycast : MonoBehaviour {
  5.     private Terrain terrain;
  6.     // Update is called once per frame
  7.     void Update() {
  8.         TreeInstance clickedTree=new TreeInstance();
  9.         if (Input.GetMouseButtonDown(0))
  10.         {
  11.             RaycastHit hit;            
  12.             TreeInstance aktStrom;
  13.             TreeInstance[] stromy = Terrain.activeTerrain.terrainData.treeInstances;
  14.             if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
  15.             {
  16.                 float minDistance = float.MaxValue;
  17.                 if (hit.collider.tag == "Enviroment")
  18.                            
  19.                     for (int i = 0; i < stromy.Length; i++)
  20.                     {
  21.                         aktStrom = stromy[i];
  22.                         float dist = Vector3.Distance(hit.point, aktStrom.position);
  23.                         if (dist < minDistance)
  24.                         {
  25.                             print(dist + "  " + minDistance+" "+ aktStrom.position);
  26.                             clickedTree = aktStrom;
  27.                             minDistance = dist;                        
  28.                      }
  29.                     Main.display = true;
  30.                     Main.text = clickedTree.heightScale.ToString();
  31.                 }
  32.             }
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement