Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 AwesumeOne · Dec 09, 2013 at 01:37 AM · variables

Click sphere for variables

I have a "galaxy" of spheres for suns and planets. I am trying to get it so that when you click a planet the script running for that game object sends its soldier count to another script where I can open a gui window. I have searched and searched for three days and still can't get it right, so if anyone is able to help I would be very grateful. Here are the two script codes. This is the code for the camera which is actually handling the GUI.

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class CameraZoom : MonoBehaviour {
 
     private float smooth = 1f;
     private Ray mouseRay;
     private Transform camTransform;
     private int camParse;
     private Vector3 targetPos;
     private Vector3 currentPos;
     private Vector3 solarPos;
     private bool isMoving;
     private RaycastHit mouseHit;
     private int viewLevel;
     private int rayLayer;
     public Texture redBar;
     public Texture blueBar;
     public Texture greenBar;
     public Texture yellowBar;
     private GameObject selectedPlanet;
     
     void Start()
     {
         //Always cache components that you will use frequently, it's much more efficient :)
         camTransform = Camera.main.transform;
         
         //Initialize target position
         currentPos = camTransform.position;
         isMoving = false;
         viewLevel = 1; //3 = planet, 2 = solar, 1 = glaxy
         targetPos = new Vector3(-75, 0 ,-110);
     }
     
     // Update is called once per frame
     void Update()
     {
         currentPos = camTransform.position;
         mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
         
         Physics.Raycast(mouseRay, out mouseHit);
         
         while(isMoving == false) //is the camera moving?
         {
             switch (viewLevel)
             {
             case 3: // planet view (no more zoom in, so only zoom out code)
                 if(Input.GetAxis("Mouse ScrollWheel") < 0)
                 {
                     targetPos = solarPos;
                     viewLevel = 2;
                     isMoving = false;
                     smooth = 0.25f;
                 }
                 break;
                         
             case 2: // solar view (zoom to either planet or galaxy view)
                 if(Input.GetAxis("Mouse ScrollWheel") < 0) //scroll back
                 {
                     targetPos = new Vector3(-75, 0 ,-110);
                     viewLevel = 1;
                     isMoving = true;
                     smooth = 1.5f;
                 }
                         
                 if(Input.GetMouseButtonDown(0) && GUIUtility.hotControl == 0)
                 {
                     if(mouseHit.collider != null)
                     {
                         targetPos = new Vector3(mouseHit.collider.gameObject.transform.position.x, mouseHit.collider.gameObject.transform.position.y, -1.5f);
                         solarPos = camTransform.position;
                         viewLevel = 3;
                         isMoving = true;
                         smooth = 0.25f;
                         selectedPlanet = mouseHit.collider.gameObject.GetComponent();
                     }
                 }
                 break;
                         
             case 1: // galaxy view (no more zoom out, so only zoom in code)
                 if(Input.GetMouseButtonDown(0) && GUIUtility.hotControl == 0)
                 {
                     if(mouseHit.collider != null)
                     {
                         targetPos = new Vector3(mouseHit.collider.transform.position.x + 15, mouseHit.collider.transform.position.y, -10);                            viewLevel = 2;
                         isMoving = true;
                         smooth = 1.5f;
                     }
                 }
                 break;
                     
             default:
                 break;
             }
                     
             break;
         }
         
         if(currentPos == targetPos)
         {
             isMoving = false;
         }
         
         camTransform.position = Vector3.MoveTowards(currentPos, targetPos, smooth);
         
     }
     
     private void OnGUI()
     {
         if(viewLevel == 3)
         {
             if(GUI.Button(new Rect(0,0, 175, 40), "Military Personnel"))
             {
             }
             
             GUI.Box(new Rect(175, 0, 175, 40), "Offical Personnel");
             GUI.Box(new Rect(Screen.width - 350, 0, 175, 40), "Military Buildings");
             GUI.Box(new Rect(Screen.width - 175, 0, 175, 40), "Ships");
             
             //add progress bars of factions
             GUI.DrawTexture(new Rect(Screen.width / 2 - 50, 0, 100, 10), redBar);
             GUI.DrawTexture(new Rect(Screen.width / 2 - 50, 10, 100, 10), blueBar);
             GUI.DrawTexture(new Rect(Screen.width / 2 - 50, 20, 100, 10), greenBar);
             GUI.DrawTexture(new Rect(Screen.width / 2 - 50, 30, 100, 10), yellowBar);
         }
     }
                     
     void SoldierFunction()
     {
         
     }
 }
 using UnityEngine;
 using System.Collections;
 
 public class PlanetStats : MonoBehaviour {
     
     //declare ~all~ variables, then initialize them.
     public int planetSoldiers1;
     public int planetSoldiers2;
     public int planetSoldiers3;
     public int planetSoldiers4;
     public int planetShips1;
     public int planetShips2;
     public int planetShips3;
     public int planetShips4;
     public int planetPersonel1;
     public int planetPersonel2;
     public int planetPersonel3;
     public int planetPersonel4;
     public float planetFaction1;
     public float planetFaction2;
     public float planetFaction3;
     public float planetFaction4;
     public int trueFaction;
     public float planetOre;
     public float planetSynth;
     public float planetEnergy;
     public int wholeOre;
     public int wholeSynth;
     public int wholeEnergy;
     
     // Use this for initialization
     void Start ()
     {
         planetSoldiers1 = 0;
         planetSoldiers2 = 0;
         planetSoldiers3 = 0;
         planetSoldiers4 = 0;
         planetShips1 = 0;
         planetShips2 = 0;
         planetShips3 = 0;
         planetShips4 = 0;
         planetPersonel1 = 0;
         planetPersonel2 = 0;
         planetPersonel3 = 0;
         planetPersonel4 = 0;
         planetFaction1 = 25.0f;
         planetFaction2 = 25.0f;
         planetFaction3 = 25.0f;
         planetFaction4 = 25.0f;
         planetOre = 0.001f;
         planetSynth = 0.001f;
         planetEnergy = 0.001f;
         trueFaction = 0;
     }
     
     // Update is called once per frame
     void Update ()
     {
         //generate the resources of the planet
         planetOre += 0.01f;
         planetSynth += 0.01f;
         planetEnergy += 0.01f;
         
         //round the resources to whole number
         wholeOre = Mathf.RoundToInt(planetOre);
         wholeSynth = Mathf.RoundToInt(planetSynth);
         wholeEnergy = Mathf.RoundToInt(planetEnergy);
         
         //set who owns the planet
         if(planetFaction1 > planetFaction2 || planetFaction1 > planetFaction3 || planetFaction1 > planetFaction4)
         {
             trueFaction = 1;
         }
         if(planetFaction2 > planetFaction1 || planetFaction2 > planetFaction3 || planetFaction2 > planetFaction4)
         {
             trueFaction = 2;
         }
         if(planetFaction3 > planetFaction1 || planetFaction3 > planetFaction2 || planetFaction3 > planetFaction4)
         {
             trueFaction = 3;
         }
         if(planetFaction4 > planetFaction1 || planetFaction4 > planetFaction2 || planetFaction4 > planetFaction3)
         {
             trueFaction = 4;
         }
         
     }
 }

That was the code for the planets. The "planetSoldiers1" is the variable I'm trying to pass to the camera code.

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 YoungDeveloper · Dec 09, 2013 at 01:52 AM 0
Share

Ins$$anonymous$$d of writing int and other variables 100 times use arrays.

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.

Follow this Question

Answers Answers and Comments

17 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Defining a variable in another script? 1 Answer

Public variable in script different for every game object. 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Get Variable From A Script Attached To a Prefab 3 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