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 AnimaCrucio · Jul 15, 2018 at 05:29 PM · camerainstantiatebuttonscrollview

Multiple Prefab Instantiation, Camera, Button and Scroll View Question

I am trying to:

Instantiate a prefab Sphere Game Object Instantiate a prefab Camera and assign it as a child of the new prefab Sphere Game Object Instantiate a prefab button that includes the script to switch the camera from the default to new Add the new button to a scroll view canvas object as a child

This is what I have so far:

     public Camera CameraPrefab, DefalutCamera;
     public Camera[] cameras;
     private int currentCameraIndex;
     public Transform GenericCanvasScrollViewObject;
     public Button ButtonPrefab;
     public GameObject SpherePrefab;

 `   void NewSphereObjectSetup()
 
     {
           GameObject newSphere = Instantiate(SpherePrefab, SetSpawnPos, Quaternion.identity);
           Camera newCamera = Instantiate(CameraPrefab);
           newSphere.transform.parent = newCamera.transform;
           Button newButton = Instantiate(ButtonPrefab);
           newButton.onClick.AddListener(SwitchToCamera(newCamera));
           newButton.transform.SetParent(GenericCanvasScrollViewObject);
     }
 
     public UnityAction SwitchToCamera(Camera anyCamera)
     {
           DefalutCamera.enabled = false;
           anyCamera.enabled = true;
     }

There are no errors until I get to the SwitchToCamera in the UnityAction. Error not all code paths return a value.

Any ideas? Or Am I on the wrong path altogether? (SetSpawnPos is brought in from another working function, please ignore the script exclusion)

Comment
Add comment · Show 2
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 ladismad · Jul 15, 2018 at 08:09 PM 0
Share

"public UnityAction SwitchToCamera" means that C# is expecting SwitchToCamera to return something of type UnityAction - perhaps replace "UnityAction" with "void", meaning that nothing is returned.

To change camera you might need to use Camera.main, which is the current camera (after you've run this twice, DefaultCamera will no longer be the active camera)

PS would you $$anonymous$$d bullet-pointing what you are trying to do? The wording makes it slightly hard to understand at the moment :P

avatar image AnimaCrucio · Jul 18, 2018 at 11:17 PM 0
Share

See reply below. Sorry I am new to this.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by AnimaCrucio · Jul 18, 2018 at 11:15 PM

At this point I will start basic and I will add the rest of what I need when I get the a working version of just one.

I need to

  • instantiate a SphereObjPrefab

  • instantiate a ButtonObjPrefab

  • add the instantiated newButtonObjPrefab to an existing Scroll View, Scroll Rect transform

  • switch the main camera to the newSphereObjPrefab on newButtonObjPrefab on Click()

That is it. The characteristics of the newSphereObjPrefab or newButtonObjPrefab, or even the camera setting don't matter at this point. I just need to make a sphere, click the button, and see it. Any help is greatly appreciated. Thanks for your response.

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

167 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

Related Questions

Is there a way to Instantiate a button prefab as a child of a Canvas? 2 Answers

Clicking Trigger 1 Answer

Scrolling scrollview filled with eventrigger objects 0 Answers

Adding a button to the content of the viewport in a scroll view through code? 0 Answers

Switch Camera On Button Press? 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