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 Thril3r · Jan 06, 2015 at 04:18 PM · arraycheckelement

Can I check the name of an element?

Can I check the name of each element with other script?

For exampel check the element 6 from "Activator Script" with "Death Script"

Something like:

If element 6 name = "Death" Do something; If element 5 name = "Score" Do something; alt text

asdqwre.jpg (105.7 kB)
Comment
Add comment · Show 3
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 Berenger · Jan 06, 2015 at 04:58 PM 0
Share

the Gamearray variable seems to be an integer array. Integers don't have names. Can you explain what you're trying to do ?

avatar image Thril3r · Jan 06, 2015 at 08:03 PM 0
Share

I want to get a randomized effect for 10 object.

Null-Score-Death. As you can see in the animation that I created.

https://www.youtube.com/watch?v=vVJHtlyXTeo

http://gyazo.com/0e9a8bb497c7631f2d55aa9238ce33fb

avatar image Thril3r · Jan 06, 2015 at 08:37 PM 0
Share

Umm... This is the script of Gamearray

function Start() { gamearray = new GameObject[10]; InvokeRepeating("ChangeArray", Random.Range(5, 15), Random.Range(5, 15)); for(var i : float = 0; i < 10; i++) { var chooseRandomly : boolean = (Random.value < 0.5); if(chooseRandomly == true) { gamearray[i] = score; } else { gamearray[i] = death; } } } function ChangeArray() { for(var i : float = 0; i < 10; i++) { var chooseRandomly : boolean = (Random.value < 0.5); if(chooseRandomly == true) { gamearray[i] = score; } else { gamearray[i] = death; } }

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by jdog98 · Jan 06, 2015 at 05:20 PM

You can acess one scripts variables with another script by using

 gameObject.GetComponent("Activator").Gamearray[ ]
Comment
Add comment · Show 9 · 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
avatar image jdog98 · Jan 06, 2015 at 05:24 PM 0
Share

so somthing like...

if(gameObject.GetComponent("Activator").Gamearray[5] == "score"){

put that in the death script

avatar image Thril3r · Jan 07, 2015 at 01:23 AM 0
Share

I get this error"'Gamearray' is not a member of 'UnityEngine.Component'."

avatar image Kiwasi · Jan 07, 2015 at 01:36 AM 0
Share

In C# it should be

 gameObject.GetComponent<Activator>().Gamearray[5] == "score"
avatar image Thril3r · Jan 07, 2015 at 01:52 AM 0
Share

"The type or namespace name `Activator' could not be found. Are you missing a using directive or an assembly reference?"

avatar image jdog98 · Jan 07, 2015 at 05:52 AM 0
Share

Thats c#.... we are using java. Just stick with what I posted and check the spelling of Gamearray. Capitalization is important. You probably used a lowercase g ins$$anonymous$$d of G

Show more comments
avatar image
0

Answer by InvincibleCat · Jan 07, 2015 at 05:55 PM

What you can do is have a static class or a Singleton that will handle your "Level". So he will store the number of death and score in the level (you can also have a DeathMax and ScoreMax values so you can adjust your design). Each time an element need to become : Null, Death or Score, it will ask the static class that will return what the element can be.

Here is the code of the manager. It replace both your Activator and your Checker scripts

 using System.Collections.Generic;
 using UnityEngine;
 
 public class ActivatorManager : MonoBehaviour
 {
     private ActivatorManager _instance = null;
     public ActivatorManager Instance
     {
         get { return _instance; }
     }
 
     public int NbScoreMax = 1;
     public int NbDeathMax = 1;
 
     public List<GameObject> Elements = null;
 
     private int _nbScore = 0;
     private int _nbDeath = 0;
 
     private void Awake()
     {
         _instance = GetComponent<ActivatorManager>();
     }
 
     private void Start()
     {
         List<int> availableElements = new List<int>();
         for (int i = 0; i < Elements.Count; i++)
         {
             availableElements.Add(i);
         }
 
         int index = Random.Range(0, availableElements.Count);
         int elementIndex = availableElements[index];
         availableElements.Remove(elementIndex);
         ActivateDeath(Elements[elementIndex]);
 
         index = Random.Range(0, availableElements.Count);
         elementIndex = availableElements[index];
         availableElements.Remove(elementIndex);
         ActivateScore(Elements[elementIndex]);
 
         for (int i = 0; i < Elements.Count; i++)
         {
             ActivateNull(Elements[availableElements[i]]);
         }
     }
 
     public void ActivateDeath(GameObject pGameObject)
     {
         if (_nbDeath < NbDeathMax)
         {
             _nbDeath++;
             DesactivateNull(pGameObject);
             pGameObject.GetComponent<Death>().enabled = true;
         }
         else
         {
             ActivateNull(pGameObject);
         }
     }
 
     public void ActivateScore(GameObject pGameObject)
     {
         if (_nbScore < NbScoreMax)
         {
             _nbScore++;
             DesactivateNull(pGameObject);
             pGameObject.GetComponent<Score>().enabled = true;
         }
         else
         {
             ActivateNull(pGameObject);
         }
     }
 
     public void ActivateNull(GameObject pGameObject)
     {
         pGameObject.GetComponent<Null>().enabled = true;
     }
 
     public void DesactivateDeath(GameObject pGameObject)
     {
         pGameObject.GetComponent<Death>().enabled = false;
         _nbDeath--;
         ActivateNull(pGameObject);
     }
 
     public void DesactivateScore(GameObject pGameObject)
     {
         pGameObject.GetComponent<Score>().enabled = false;
         _nbScore--;
         ActivateNull(pGameObject);
     }

     public void DesactivateNull(GameObject pGameObject)
     {
         pGameObject.GetComponent<Null>().enabled = false;
     }
 }
 

Comment
Add comment · Show 25 · 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
avatar image Thril3r · Jan 08, 2015 at 07:08 PM 0
Share

Ok, let me remake the question, keep in $$anonymous$$d that I m newbie.

This is what i tried to do:

The ActivatorScript will randomize between Null-Death-Score

CheckerScript will check the elements and after check will activate a script (DeathScript, ScoreScript, NullScript) from a gameobject that corespond to his element (gameobject 1 - element 0).

But I saw that I can t check the element in this way.....

If you think that there is another way please let me know.

I want to somehow control the time when they appear/disapear and limit them to 2-3 score/death and rest of them to be null. Is that even possible?

Thank you all for your answers! I really appreciate this :)

How I tried

helphelp.jpg (321.1 kB)
avatar image InvincibleCat · Jan 08, 2015 at 07:14 PM 0
Share

I don't really understand what you are trying to do... What do you want to do? Not in technical terms but more in concept terms

avatar image Thril3r · Jan 08, 2015 at 09:39 PM 0
Share

The player has to pass from right to left and vice versa. This is why I try to make the objects appear randomly.

avatar image InvincibleCat · Jan 08, 2015 at 09:43 PM 0
Share

Do you have any screenshot of you want to do?

avatar image Thril3r · Jan 08, 2015 at 10:29 PM 0
Share

Umm... nope, but you can see in video what I want, except that there is no player to go from side to side.

https://www.youtube.com/watch?v=vVJHtlyXTeo

Show more comments

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Check array slot against corresponding slot in another array? 1 Answer

Check if an array contains certain number combos? 1 Answer

Swapping elements of an array 1 Answer

Lists: Avoiding ArgumentOutOfRangeException: Argument is out of range errors 1 Answer

bounds checking a list? 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