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 Lomusire · Dec 02, 2020 at 12:33 AM · gameobjectunityeditor

How to make a game object from several game objects in Unity?

Dear Unity fourm I have programmed a great music game. Unfortunately there is a problem. In my game there are so many objects that my smartphone can't load the game properly. I have nowhere to find out how to make an object out of many objects. If someone knows how to do it I would be very happy!

My Script:

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;

public class line : MonoBehaviour {

 //Please attach me to the line, then set  dline,tail,mcamera,road,decorates,dieeff.
 //You can add more to make this better!
 public GameObject dline, tail, mcamera, road, decorates, dieeff;

 private GameObject tempgo, tempdia, tempcr;

 public bool direction, alive, start, load, roadmaker;

 public float cameraspeed, temprm;

 public Vector3 offset, tempcrgo;

 private GameObject[] dia, cr;

 List<GameObject> go = new List<GameObject>();

 void Start()
 {
     start = false;
     load = true;
     alive = true;
     //find diamonds and crowns
     dia = GameObject.FindGameObjectsWithTag("dia");
     cr = GameObject.FindGameObjectsWithTag("crown");
     //
 }

 void Update()
 {
     if (load == true)
     {
         //save the initial distance between camera and line
         offset = mcamera.transform.position - dline.transform.position;
         cameraspeed = 0.03f;
         load = false;
         //
     }
     //restart
     if (Input.GetKeyDown(KeyCode.R) == true)
     {
         SceneManager.LoadScene("main");
     }
     //
     if (start == false && alive == true)
     {//start game
         if (Input.GetMouseButtonDown(0) == true || Input.GetKeyDown(KeyCode.Space) == true)
         {
             start = true;
             dline.GetComponent<AudioSource>().enabled = true;
         }

     }//

     if (start == true)
     {//turn
         if (Input.GetMouseButtonDown(0) == true || Input.GetKeyDown(KeyCode.Space) == true)
         {
             if (direction == true)
             {
                 direction = false;
             }
             else
             {
                 direction = true;
             }
         }
     }//
      //build road/wall more efficiently
     if (roadmaker)
     {
         temprm += 1;
         //why there is temprm?to reduce the ammount of roads
         //why build one when click?to ensure there is road/wall when line turns(or it will look weird)
         if (temprm % 6 == 1 || Input.GetMouseButtonDown(0) == true || Input.GetKeyDown(KeyCode.Space) == true)
         {
             GameObject.Instantiate(road, dline.transform.position + new Vector3(3, 0, -3), dline.transform.rotation);
             GameObject.Instantiate(road, dline.transform.position + new Vector3(-3, 0, 3), dline.transform.rotation);
         }// // //
     }
     else
     {//when you play ...I dont put the part in Update but if(roadmaker) because these actions will create new gameobject and interfere the copying of road
         GameObject.Instantiate(tail, dline.transform.position, dline.transform.rotation);
         if (Input.GetMouseButtonDown(0) == true || Input.GetKeyDown(KeyCode.Space) == true)
         {
             if (direction == true)
             {
                 go.Add(GameObject.Instantiate(decorates, dline.transform.position + new Vector3(8, -9, -5), dline.transform.rotation));
             }
             else
             {
                 go.Add(GameObject.Instantiate(decorates, dline.transform.position + new Vector3(-5, -9, 8), dline.transform.rotation));
             }
         }
     }//
 }

 void FixedUpdate()
 {//smooth camera
     mcamera.transform.position = Vector3.Lerp(mcamera.transform.position, offset + dline.transform.position, cameraspeed);
     //
     //some 'animations' .I didnt use animation component because I dont know how it works in Unity :(
     foreach (GameObject tempgo in go)
     {
         tempgo.transform.position += new Vector3(0, 0.2f, 0);
     }

     foreach (GameObject tempdia in dia)
     {
         tempdia.transform.localEulerAngles += new Vector3(0, 2, 0);
         if (Mathf.Abs(dline.transform.position.x - tempdia.transform.position.x) < 1 && Mathf.Abs(dline.transform.position.z - tempdia.transform.position.z) < 1 && tempdia.transform.localScale.z > 0)
         {
             tempdia.transform.localScale -= new Vector3(0.3f, 0.3f, 0.3f);
         }
     }
     foreach (GameObject tempcr in cr)
     {
         tempcr.transform.localEulerAngles += new Vector3(0, 2, 0);
         if (Mathf.Abs(dline.transform.position.x - tempcr.transform.position.x) < 2 && Mathf.Abs(dline.transform.position.z - tempcr.transform.position.z) < 2 && tempcr.transform.localScale.z > 0)
         {
             tempcr.transform.localScale -= new Vector3(0.26f, 0.26f, 0.26f);
             tempcrgo = tempcr.transform.position;
         }
         if (tempcr.transform.localScale.z <= 0)
         {
             tempcrgo += new Vector3(Random.Range(-2f, 2f), Random.Range(-1f, 2f), Random.Range(-2f, 2f));
             tempcr.GetComponent<Light>().enabled = true;
             tempcr.transform.position = Vector3.Lerp(tempcr.transform.position, tempcrgo, 0.02f);

         }
     }
     //
     if (start == true && alive == true)
     {//how the line move
         if (direction == true)
         {
             dline.transform.position += new Vector3(0.3f, 0, 0);
         }
         else
         {
             dline.transform.position += new Vector3(0, 0, 0.3f);
         }
     }//
 }

 void OnCollisionEnter(Collision x)
 {//when die...
     if (x.collider.tag == "wall")
     {
         alive = false;
         mcamera.GetComponent<AudioSource>().enabled = true;
         dieeff.SetActive(true);
     }// 
      //when complete the level...
     if (x.collider.tag == "Finish")
     {
         offset = offset + offset + offset + offset;
         cameraspeed = 0.01f;
     }//
 }

}

`

Game view

Video Link:

https://drive.google.com/file/d/1dqIqu6tx5thNbCJ1jNndXEJY_a9JJGGe/view?usp=sharing

2020-11-28-13-30-00-super-shadow-cube-2-microsoft.png (117.4 kB)
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

221 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

How to keep a GameObject inside a collider? 3 Answers

gameobject.transform.parent not assinged after deploy 0 Answers

Unwanted Cube GameOjbect gets generated upon playing any scene? 1 Answer

Must I always create a public variable for Prefabs? 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