• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by minefriek · Aug 26, 2015 at 12:35 PM · javascriptarrayarraysrts

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

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image minefriek · Aug 27, 2015 at 02:48 PM 0
Share

sorry thats supposed to be function update not function sstart

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

27 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

My array does not update when object is destroyed. How do I fix it? (java) 2 Answers

Index out of bounds even tho it shouldnt be [Javascript] 1 Answer

How to create an auido array (JavaScript) 1 Answer

I have an array problem 1 Answer

Random an Array to push to another Array 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges