Hi, i need help, In the scene, I have the cube Player (with arms and point spawnPoint1) and cube Enemy. The player moves on the plane (with A * Pathfinding Project 2.5http://forum.unity3d.com/viewtopic.php?t=43822)left mouse button and chooses the enemy using the right mouse button. What do I need to add the script to the player turned and attacked(shoot) the enemy selected, pressing the left mouse button? Player script MainPlayer.cs Code (csharp): using UnityEngine; using System.Collections; public class MainPlayer : MonoBehaviour { private CharacterController controller; public Transform bullitPrefab; public Transform Spawn; private GameObject fireBullit; void Update () { Shoot(); } public void Shoot () { } } Camera script Player.cs Code (csharp): // Attach this script to the scene camera // Create and apply a tag labeled 'SelectableActor' to all selectable game objects; // Right mouse click to select left click to do something to them. using UnityEngine; using System.Collections; public class Player : MonoBehaviour { private Actor currentTargetedActor; void Update() { // Check if the user right mouse clicked if (Input.GetMouseButtonDown(1)) { Debug.Log(""); Ray ray = camera.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; if (Physics.Raycast(ray, out hitInfo, Mathf.Infinity)) { // you could just check if you have a component call 'Actor' attached instead // of using tags if you wanted. if (hitInfo.collider.tag == "SelectableActor") { Actor selectedActor = (Actor)hitInfo.collider.gameObject.GetComponent("Actor"); // Check we don't already have the actor selected if (currentTargetedActor != selectedActor) { if (currentTargetedActor != null) currentTargetedActor.selected = false; selectedActor.selected = true; currentTargetedActor = selectedActor; } Debug.Log("You have selected: " + currentTargetedActor.gameObject.name); } else { //We hit something but is wasn't a selectedable actor so deselect current actor if we have one selected. if (currentTargetedActor != null) { currentTargetedActor.selected = false; currentTargetedActor = null; } } } else { //We hit nothing so deselect actor if we have one selected. if (currentTargetedActor != null) { currentTargetedActor.selected = false; currentTargetedActor = null; } } } else if(Input.GetMouseButtonDown(0) currentTargetedActor) { //Fire a projectile/heal an actor // MainPlayer mp = (MainPlayer)gameObject.GetComponent("MainPlayer"); // mp.Shoot(); // currentTargetedActor.Actor(); //.Shoot(); } } } Player and Enemy script (enemy has the type of enemy) Actor.cs Code (csharp): // Attach to all selectable game objects using UnityEngine; using System.Collections; public class Actor : MonoBehaviour { public enum ActorTypes {Enemy, Friend, Player}; public ActorTypes actorType; private bool isSelected; // Called when selected and deselected public bool selected { get { return isSelected; } set { isSelected = value; } } //Called when this actor is selected and user right mouse clicks in the scene. public void Action() { switch (actorType) { case ActorTypes.Enemy: Debug.Log("Doing Something good to: " + this.gameObject.name); break; case ActorTypes.Friend: Debug.Log("Doing Something good to: " + this.gameObject.name); break; case ActorTypes.Player: Debug.Log("Doing Something good to: " + this.gameObject.name); break; } } } project - scene _MIAN http://rs568.rapidshare.com/files/354785230/NEWRTS.zip
Hi, welcome to the forum! I'm not quite sure what you mean. Do you want the player to turn as it is moving toward the enemy or turn to face the enemy, or do you want the enemy to face the player as it moves or... ?