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 Goofball · Aug 29, 2013 at 07:51 PM · parentingchild objectreferencingdrag and dropstoring

How do I hold an object within one of my spheres, to where I can click the sphere and activate the object?

What I have right now is a primary sphere called the IncomeSphere, and on the OnMouseDown() function of that IncomeSphere there are 4 identical spheres that are instantiated called ActionSpheres. Within the OnMouseOver() of both the IncomeSphere and the ActionSpheres they fade in/out identifying which one is selected. On MouseUp() the ActionSpheres are destroyed. I want there to be 4 individual items within each of the ActionSpheres when they instantiate.

There are 100 gameboard like plate objects that are instantiated at the beginning of the level in the form of a 10x10 field (They have the same fade in/out highlight function). Overall I want an object from one of those 4 ActionSpheres to be activated and instantiate in the OnMouseUp() function of those plates. using UnityEngine; using System.Collections; using System.Collections.Generic;

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class IncomeSphere : MonoBehaviour {
     //Constants for location
     public const float _offSetY = 58.0f;
     public const float _offSetZ = 166.0f;
     public const int _primarySphere = 296;
     
     //Constant for the slots unlocked
     public const int _slotsAvailable = 4;
     
     //Sets the Actoin Sphere prefab
     public GameObject actionSphere;
     
     //Creates three arrays to instantiate the Action Spheres
         //int[] _aSlot (actionSlot) to adjust the PrimarySphere(X) value
         //Vector3[] _aSpherePos (actionSpherePosition) to reapply the vectors
         //GameObject[] _aSphere (actionSphere) to hold the instantiated sphere
     private GameObject[] _aSphere = new GameObject[_slotsAvailable];
     private Vector3[] _aSpherePos = new Vector3[_slotsAvailable];
     private int[] _aSlot = new int[_slotsAvailable];
     
     
     
     
     
     //Sets the transparency state of the Action Spheres
     private bool alphaState = false;
     
     // Use this for initialization
     void Start() {
         //Recalculates the vectors of each Action Sphere
         for (int cnt = 0; cnt < _slotsAvailable; cnt++) {
             _aSlot[cnt] = _primarySphere + (cnt + 1);
             _aSpherePos[cnt] = new Vector3(_aSlot[cnt], _offSetY, _offSetZ);
             //Debug.Log(_aSpherePos[cnt] + " is the position for slot " + cnt);
         }
         
         renderer.material.color = new Color(0, .4f, .4f, .14f);
         //Debug.Log ("Color is now " + renderer.material.color);
     }
     
     // Update is called once per frame
     void Update (){
         
     }
     
     void OnMouseOver() {        
         #region Fade In
         //If the alpha's state is set to false and rendered below a float of 0.84 
         if (alphaState == false) {
             if (renderer.material.color.a < .84f) {
                 //Then increase the alpha by framerate * 2 and print progress
                 renderer.material.color += new Color(0, 0, 0, Time.deltaTime  * 2);
             //Unless the alpha is rendered at a float of 0.84
             } else {
                 //Then set the alpha's state to true
                 alphaState = true;
             }
         }
         #endregion
         
         #region Fade Out
         //If the alpha's state is set to false and is rendered above a float of 0.14
         if (alphaState == true) {
             if (renderer.material.color.a > .14f) {
                 //Then decrease the alpha by framerate * 2 and print progress
                 renderer.material.color -= new Color(0, 0, 0, Time.deltaTime * 2);
             //Unless the alpha is rendered at a float of 0.14
             } else {
                 //Then set the alpha's state to false
                 alphaState = false;
             }
         }
         #endregion
     }
     
     void OnMouseDown() {
         #region Creates the Action Spheres
         //Assigns space for Action Spheres
         
         //Creates the Action Spheres
         for(int cnt = 0; cnt < _slotsAvailable; cnt++) {
             Debug.Log(_aSpherePos[cnt] + " is the position for slot " + (cnt + 1));
             _aSphere[cnt] = Instantiate(actionSphere, _aSpherePos[cnt], Quaternion.identity)as GameObject;
         }
         #endregion
     }
     
     void OnMouseUp() {
         //Creates a sphere for an action to be set
         for (int cnt = 0; cnt < _slotsAvailable; cnt++) {
             Debug.Log("Slot " + (cnt + 1) + " has been destroyed");
             Destroy(_aSphere[cnt]);
         }
     }
     
     //If the mouse exits the game object
     void OnMouseExit() {
         //Then revert the rendering to it's original float
         renderer.material.color = new Color(0, .4f, .4f, .14f);
         Debug.Log ("Color reset to " + renderer.material.color);
     }
 }
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

16 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

Related Questions

Can 3d objects be children of a canvas? 1 Answer

Can't proberly animate child. Causes slingshot effect 0 Answers

how to reference child in a prefab within a prefab 0 Answers

Why is parenting not working? 0 Answers

Mesh gets squashed after parenting to camera. 0 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