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 StuwuStudio · Mar 18, 2015 at 05:26 AM · instantiatedestroydistanceloopcalculate

Generate randoms planets with a specific script

Hi everybody! I have a litte problem for adapt a script to a multiple planets script, my first script is for calculate distance between two object and destroy the object if the object is too far of the player and instantiate if the player come back.

 using UnityEngine;
 using System.Collections;
 
 public class Calculate : MonoBehaviour {
 
     float distance;
     public Transform object1;
     public Transform object2;
     public Transform ozone;
     Transform planets;
     public Texture2D texture1 = null;
     public Texture2D texture2 = null;
     public Texture2D texture3 = null;
 
     void OnGUI () {
         string distanceText = System.Convert.ToString(distance);
         GUI.Label (new Rect(Screen.width/56, Screen.height/3, 200, 200), distanceText);
     }
 
     // Use this for initialization
     void Start () {
     }
     
     // Update is called once per frame
     void Update () {
 
         //Calculate Distance
         distance = Vector3.Distance (object1.transform.position, object2.transform.position);
 
         //Detecte distance
         if(distance <= 200) {
             object2.transform.renderer.material.mainTexture = texture1;
         }
 
         //Detecte distance
         if(distance >= 400) {
             object2.transform.renderer.material.mainTexture = texture2;
         }
 
         //Detecte distance
         if(distance >= 600) {
             object2.transform.renderer.material.mainTexture = texture3;
         }
 
         //Detecte distance
         if(distance <= 100) {
             object2.transform.renderer.enabled = false;
             object2.transform.collider.enabled = false;
 
             if(GameObject.Find("Planets01(Clone)") == false && GameObject.Find("Planets01") == false) {
                 Instantiate(Resources.Load("Planets01"), ozone.transform.position, Quaternion.identity);
 
             }
             if(GameObject.Find("Planets01") == false && GameObject.Find("Planets01(Clone)") == false) {
                 Instantiate(Resources.Load("Planets01"), ozone.transform.position, Quaternion.identity);
                 
             }
         }
 
         //Detecte distance
         if(distance >= 100) {
             object2.transform.renderer.enabled = true;
             object2.transform.collider.enabled = true;
             
             Destroy(GameObject.Find("Planets01"));
             Destroy(GameObject.Find("Planets01(Clone)"));
         }
     }
 }

the second is an random planets distributor (look down) but what i want to do is when i approche a planets, there replace the "false planet (ozone)" by the real "planets01" and the inverse when i go away. (this script don't really work)

 using UnityEngine;
 using System.Collections;
 
 public class PlanetsRandomGenerating : MonoBehaviour {
 
     public GameObject planet01;
     public GameObject Ozone;
     public float planetsNumber;
     GameObject newPlanets;
     string planetsName;
     float floatName;
     float near;
 
     float distance;
     Transform Allpl = GameObject.FindGameObjectsWithTag("Planets01");
     Transform Player = GameObject.FindGameObjectWithTag("Player");
     public Material skybox1 = null;
     public Material skybox2 = null;
 
     // Use this for initialization
     void Start () {
         for(int i = 1; i <= planetsNumber; i++) {
             floatName = floatName + 1f;
             Vector3 position01 = new Vector3(Random.Range(-10000.0f, 10000.0f), Random.Range(-10000.0f, 10000.0f), Random.Range(-10000.0f, 10000.0f));
             newPlanets = (GameObject)Instantiate(planet01, position01, Quaternion.identity); //Assing the skybox script to the current planets create a cuurent pla for each planets
             planetsName = System.Convert.ToString(floatName);
             newPlanets.name = planetsName;
             Instantiate(Ozone, position01, Quaternion.identity);
         }
     }
     
     // Update is called once per frame
     void Update () {
         near = Vector3.Distance (Player.transform.position, Allpl.transform.position);
         Debug.Log(near);
         //distance = Vector3.Distance (Player.transform.position, Unknow.transform.position);
     
     }
 }

help please! thank

Comment
Add comment
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

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

2 People are following this question.

avatar image avatar image

Related Questions

Trying to not make an infinite loop 0 Answers

Creating more objects the closer you get 0 Answers

For loop with Vector3.distance does the loop like 20 times per loop 1 Answer

Having problems with destroying, instantiating 0 Answers

Instantiate Pre-fab clone altered on Instantiate 2 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