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 Robomaster · Jan 11, 2014 at 03:51 AM · variablesmethodradiuscalls

Multiple Method Calls

Hello so i currently have a question about my hitCollider Method

public void Check(Vector3 myCenter, float myRadius) {

     Collider[] hitColliders = Physics.OverlapSphere(myCenter, myRadius);
     int i = 0;
     if(i < hitColliders.Length)
     {
         Plains = GameObject.Find("Plains");
         Tile t = (Tile)Plains.GetComponent("Tile");
             t.AdjustCurrentValue1(+1);
     }
 }

What its doing right now is checking to see if there are any objects within the Spheres radius and if so, it calls a method from another script and adjusts its variable. Well all this can do right now is adjust the variable of one script. Now say there are multiple objects in the spheres radius which there will be, how could i adjust the code so that it calls the method from each object and adjusts each ones variable. I was thinking of adjusting the GameObject.Find to something like tag.Find(if theres even a command for that) so that it would search for all objects with that tag. But I'm not sure if there is such a command. I currently have it working with just one object but im going to need multiple objects since what is going to be happening is that whatever tiles are in its radius are going to light up blue to let the player know his movement area. So this code has to adjust the variable in each of the tiles so that they can light up blue.

Comment
Add comment · Show 4
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 Invertex · Jan 11, 2014 at 04:26 AM 0
Share

Why not just put a trigger on the change color blocks, then call a change in it's own local variable OnTriggerEnter, and change it back OnTriggerExit?

avatar image Robomaster · Jan 11, 2014 at 04:49 AM 0
Share

Thanks but I tried that, the ones already inside the radius wouldn't change color, I'm guessing because they didn't enter the area, they were already in it.

avatar image Invertex · Jan 11, 2014 at 05:00 AM 0
Share

Use OnTriggerStay ins$$anonymous$$d of OnTriggerExit, then, or have you tried that as well?

avatar image Robomaster · Jan 11, 2014 at 01:39 PM 0
Share

No i haven't tried that, that might work though. But i got the script running correctly though now, Thanks for the help!

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by robertbu · Jan 11, 2014 at 04:30 AM

I have to guess a bit here. I'm assuming that your OverlapSphere() call is finding object the 'Tile' script attached. If so, you can do something like:

 Collider[] hitColliders = Physics.OverlapSphere(myCenter, myRadius);
 foreach (Collider col in hitColliders) {
     Tile t = col.GetComponent<Tile>();
 
     if (t != null) {
         t.AdujstCurrentValue1(1);
     }
 }

I don't know what the '+' is the '+1' is all about. In addition, don't use the string version of 'GetComponent'. Use the generic version as I've done here.

Comment
Add comment · Show 3 · 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 Robomaster · Jan 11, 2014 at 04:54 AM 0
Share

Yes for every object in its radius which will be a tile, they will all have the Tile script attached. And Thank you i can see how this will work but the way it is right now unity is saying: Type Tile' does not contain a definition for AdujstCurrentValue1' and no extension method AdujstCurrentValue1' of type Tile' could be found i tried messing around with the parameters at the end of GetComponent(); but i could figure it out, any ideas?

avatar image robertbu · Jan 11, 2014 at 06:18 AM 0
Share

$$anonymous$$ake sure the 'AdjustCurrentValue1()' method is public and that the name matches exactly to what you are using here. Note I compiled that bit of code (including a quick Tile script with an 'AdjustCurrentValue1()' method) to be absolutely sure it would compile.

avatar image Robomaster · Jan 11, 2014 at 01:38 PM 0
Share

Yep i see the problem AdjustCurrentValue1() was misspelled, it was spelled AdujstCurrentValue(); facepalm It works flawlessly now thank you!

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

19 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

Related Questions

How do I get a variable from another script and share the value of that variable between scripts? 1 Answer

Problem with var in C# (Vector3, transform and similiar) 1 Answer

cant change variable from a method? timer stays at 0! 1 Answer

Calling a variable based on a variables name? 1 Answer

Scriptable object variable not updating when changed, only when game stopped 1 Answer


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