Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 FuriousCreeper · Mar 31, 2019 at 02:07 PM · characterloadloading

Load character from character selector to the game scene

Hi everyone!

I'm developing a mobile game: It's a game where you have a cannon on wheels and you have to shoot the boxes to get points.

alt text

Here there is a menu to choose his cannon. When you press GO !, the chosen cannon should appear on the gamescene (the cannons are already on the gamescene but are disabled). But unfortunately it does not work.

Here are the scripts I did for the guns to load :

 using System.Collections;
 using UnityEngine;
 
 public class DataHandler : MonoBehaviour
 {
     // Start is called before the first frame update
 
     public int cartSel;
 
     void Awake()
     {
         GameObject.DontDestroyOnLoad(this.gameObject);
     }
 
     void Start()
     {
         cartSel = 1;
     }
 
     public void selectCart(int a)
     {
         cartSel = a;
     }
 }

and this one

 using UnityEngine;
 using System.Collections;
 
 public class DataImplementer : MonoBehaviour {
 
 
     int cartSelected;
 
     GameObject Default;
     GameObject Gunner;
     GameObject Titan;
     GameObject Berserk;
     GameObject Schockwave;
     GameObject Undertaker;
     GameObject Sparky;
 
     void Start(){
         cartSelected = GameObject.Find("DataHandler").GetComponent<DataHandler>().cartSel;
 
         if (cartSelected == 1) {
             Default.SetActive(true);
             Gunner.SetActive(false);
             Titan.SetActive(false);
             Berserk.SetActive(false);
             Schockwave.SetActive(false);
             Undertaker.SetActive(false);
             Sparky.SetActive(false);
         }
 
         else if (cartSelected == 2) {
             Default.SetActive(false);
             Gunner.SetActive(true);
             Titan.SetActive(false);
             Berserk.SetActive(false);
             Schockwave.SetActive(false);
             Undertaker.SetActive(false);
             Sparky.SetActive(false);
         }
 
         else if (cartSelected == 3) {
             Default.SetActive(false);
             Gunner.SetActive(false);
             Titan.SetActive(true);
             Berserk.SetActive(false);
             Schockwave.SetActive(false);
             Undertaker.SetActive(false);
             Sparky.SetActive(false);
         }
 
         else if (cartSelected == 4) {
             Default.SetActive(false);
             Gunner.SetActive(false);
             Titan.SetActive(false);
             Berserk.SetActive(true);
             Schockwave.SetActive(false);
             Undertaker.SetActive(false);
             Sparky.SetActive(false);
         }
 
         else if (cartSelected == 5) {
             Default.SetActive(false);
             Gunner.SetActive(false);
             Titan.SetActive(false);
             Berserk.SetActive(false);
             Schockwave.SetActive(true);
             Undertaker.SetActive(false);
             Sparky.SetActive(false);
         }
 
         else if (cartSelected == 6) {
             Default.SetActive(false);
             Gunner.SetActive(false);
             Titan.SetActive(false);
             Berserk.SetActive(false);
             Schockwave.SetActive(false);
             Undertaker.SetActive(true);
             Sparky.SetActive(false);
         }
 
         else if (cartSelected == 7) {
             Default.SetActive(false);
             Gunner.SetActive(false);
             Titan.SetActive(false);
             Berserk.SetActive(false);
             Schockwave.SetActive(false);
             Undertaker.SetActive(false);
             Sparky.SetActive(true);
         }
 
 
 
 
 
 
 
     }
 
 
 }

I hope someone could fix my problem

Thanks :) (sry for my bad english)

unity.png (153.2 kB)
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 RobAnthem · Mar 31, 2019 at 04:00 PM 0
Share

You need to look into prefabs and instantiation. Also some arrays, lists, and general organization could do you some good. Not trying to sound rude, but what you are attempting is incredibly simple for program$$anonymous$$g in Unity. So you just need to do some more learning. I'll point you in the right direction though. Create your turret prefabs, give them an ID or something, and either load them from resources or put the references to the turrets in both scenes. When the player selects the turret, set a field in the player data class (if you made one) or in some static field area for the ID of the turret. When you start your play scene, get the ID of the turret you selected in main screen and instantiate that from your list of turret references at the desired spawn point. Does this make sense?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by unity_J016ZU_VZQzYAg · Mar 31, 2019 at 07:24 PM

Could it be, that the Start Method got already called, so nothing is actually happening when you select a canon?
Add a method to the DataImplementer Script like showSelectedCanon(int sel) and put the body of the start method as body of this method.
Like that:

      void showSelectedCanon(int sel){
          cartSelected = sel;
  
          if (cartSelected == 1) {
              Default.SetActive(true);
              Gunner.SetActive(false);
              Titan.SetActive(false);
              Berserk.SetActive(false);
              Schockwave.SetActive(false);
              Undertaker.SetActive(false);
              Sparky.SetActive(false);
          }
  
          else if (cartSelected == 2) {
              Default.SetActive(false);
              Gunner.SetActive(true);
              Titan.SetActive(false);
              Berserk.SetActive(false);
              Schockwave.SetActive(false);
              Undertaker.SetActive(false);
              Sparky.SetActive(false);
          }
  
          else if (cartSelected == 3) {
              Default.SetActive(false);
              Gunner.SetActive(false);
              Titan.SetActive(true);
              Berserk.SetActive(false);
              Schockwave.SetActive(false);
              Undertaker.SetActive(false);
              Sparky.SetActive(false);
          }
  
          else if (cartSelected == 4) {
              Default.SetActive(false);
              Gunner.SetActive(false);
              Titan.SetActive(false);
              Berserk.SetActive(true);
              Schockwave.SetActive(false);
              Undertaker.SetActive(false);
              Sparky.SetActive(false);
          }
  
          else if (cartSelected == 5) {
              Default.SetActive(false);
              Gunner.SetActive(false);
              Titan.SetActive(false);
              Berserk.SetActive(false);
              Schockwave.SetActive(true);
              Undertaker.SetActive(false);
              Sparky.SetActive(false);
          }
  
          else if (cartSelected == 6) {
              Default.SetActive(false);
              Gunner.SetActive(false);
              Titan.SetActive(false);
              Berserk.SetActive(false);
              Schockwave.SetActive(false);
              Undertaker.SetActive(true);
              Sparky.SetActive(false);
          }
  
          else if (cartSelected == 7) {
              Default.SetActive(false);
              Gunner.SetActive(false);
              Titan.SetActive(false);
              Berserk.SetActive(false);
              Schockwave.SetActive(false);
              Undertaker.SetActive(false);
              Sparky.SetActive(true);
          }
 
      }


Now if you call that method after selecting a canon, it should work. Like:

      public void selectCart(int a)
      {
          cartSel = a;
          // call showSelectedCanon here
      }


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

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

144 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

Related Questions

Save & Load Game question 3 Answers

Android load/unload times 0 Answers

Occasionally losing data (animator controller transitions and animator's parameters, animation states remain) 0 Answers

Problem with saving the transform of the player 1 Answer

How to have character custimation to save and be used in an mmo 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