以ä¸ã®æ§ãªã¤ã¡ã¼ã¸ã§æ§æã
é»è²ã®Cubeã®çµåã â Player(ç ²å°çãªãã®)
赤ãç·ãéã®Cube â ã¿ã¼ã²ãã
ã¿ã¼ã²ãããã¯ãªãã¯ããã¨Playerããã®æ¹åãåãã¾ãã
å®éã®åä½ã¯こちらã§è©¦ãã¾ããã½ã¼ã¹ã³ã¼ãã¯こちらã
ã¿ã¼ã²ããã«ã¯ä»¥ä¸ã®JavaScript
ãClickBehaviourScript.jsã
private var playerBehaviourScript: PlayerBehaviourScript; function Start () { var playerObj : GameObject = GameObject.FindWithTag("Player"); playerBehaviourScript = playerObj.GetComponent(PlayerBehaviourScript); } function OnMouseDown () { var ray : Ray; var hit : RaycastHit; ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, hit, 100)) { print(hit.collider.gameObject); playerBehaviourScript.TargetLookAt(hit.collider.gameObject.transform); } }
Playerã«ã¯ä»¥ä¸ã®JavaScriptãè¨å®
ãPlayerBehaviourScript.jsã
function TargetLookAt (target : Transform) { transform.LookAt(target); }
ã¿ã¼ã²ãããã¯ãªãã¯ããã OnMouseDown ã¤ãã³ããçºçãããã®ä¸ã§Playerã®JavaScriptã® TargetLookAt () ãå¼ã³ãPlayerãèªå(ã¿ã¼ã²ãã)ã®æ¹ãåããã¾ãã