- Home /
Having Multiple Controllable FPS Units Selected From A Singular RTS Mode?
Hello
This is a problem thats been wracking my head for a month now due to how hard it is for my head to wrap around the underlying concepts. My Game is set up in a way where I can control units via an RTS mode but also select via mouse click using ScreenPointToRay in order to assume controll of said unit. The second part is where im having a bit of trouble concerning the topic of multiple units where i can control any one of the multiple. I know it has something to do with arrays and possibly tags but appart from that I have no Idea
This is the code in its current state
#pragma strict
var camera1 : Camera;
var camera2 : Camera;
var target : Transform;
var target2 : Transform;
var objprefab : Transform;
private var objspawned : Transform;
function start () {
if (Input.GetMouseButtonDown(0) && (camera1.enabled == true)) {
Debug.Log("Clicked ");
var hit: RaycastHit;
var ray: Ray = camera1.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray,hit)) {
Debug.Log("Clicked " + hit.transform.name);
if (hit.transform.gameObject == target) {
Debug.Log("targ");
camera1.enabled = false;
camera2.enabled = true;
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
(GameObject.Find("BaseChar").GetComponent("FirstPersonController") as MonoBehaviour).enabled = true;
(GameObject.Find("StratShell").GetComponent("RTSCam") as MonoBehaviour).enabled = false;
}
else if (hit.transform == target2) {
objspawned = Instantiate (objprefab, hit.point, Quaternion.identity);
GameObject.Find("BaseChar").GetComponent.<AIPath>().target = objspawned.transform;
Destroy (GameObject.Find("Pin(Clone)"), 0.1f);
}
}
}
}
camera 1 is the rts camera camera 2 is the fps camera target is the unit target 2 is the terrain allowing for me to drop a 'pin' that astar then picks up and sets as the transform for pathfinding objprefab is the pin objspawned is a private var that does other things i cant remember the specifics of
i think thats everything you'll need to help me. where can I find some referencing or some code samples thaat would allow me to employ multiple units?
Thankyou so much in advance :D
Minefriek
sorry thats supposed to be function update not function sstart
Your answer
Follow this Question
Related Questions
How to set parents of all objects in an array? 1 Answer
I have an array problem 1 Answer
How do to you save time for each player and display it? 2 Answers
What is a 2D Array? 3 Answers
Distance error: Cannot cast from source type to destination 0 Answers