Advertisement
Guest User

Untitled

a guest
Oct 8th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.48 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3.  
  4. namespace BehaviorDesigner.Runtime.Tasks.Basic.UnityInput
  5. {
  6.     [TaskCategory("Basic/Input")]
  7.     [TaskDescription("Stores the mouse clicked object.")]
  8.     public class DetectClickedObject : Action
  9.     {
  10.         [Tooltip("The stored result")]
  11.         public SharedGameObject storeResult;
  12.         [Tooltip("ObjectName")]
  13.         public SharedString ObjectName;
  14.         [Tooltip("Tagrestriction")]
  15.         public string tagname = "Player1";
  16.  
  17.         public override TaskStatus OnUpdate()
  18.         {
  19.  
  20.             if (Input.GetMouseButtonDown(0))
  21.             {
  22.                 var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  23.                 RaycastHit hit;
  24.  
  25.                 if (Physics.Raycast(ray, out hit, 100))
  26.                 {
  27.                     if (hit.collider.tag == tagname)
  28.                     {
  29.                         storeResult = GameObject.Find(hit.collider.name);
  30.                         GameObject.Find("ChoosenAssistantButton").GetComponentInChildren<Text>().text = hit.collider.name;
  31.                         ObjectName = hit.collider.name;
  32.                         //GlobalVariables.Instance.SetVariable("AssistantChosenObj", storeResult);
  33.                         Debug.Log(hit.collider.name);
  34.                     }
  35.                 }
  36.             }
  37.  
  38.             return TaskStatus.Success;
  39.         }
  40.  
  41.         public override void OnReset()
  42.         {
  43.             storeResult = null;
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement