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 ragnaros100 · Jun 13, 2012 at 10:14 PM · c#colliderarrayforeach

I have to set a Collider[] to Collider - what do?

I have searched almost the entire Unity Answers for a similar questio. Unity script refference and google havent helped me either. But I get this really wierd error:

Script error: OnTriggerEnter This message parameter has to be of type: Collider The message will be ignored.

I'm sure this is a really easy fix, but I really have no clue how to fix it though.

here's a snippet of my code:

Edit: Well...the variable names might be a bit hard to understand. also I really suck at commenting while I write.

 void OnTriggerEnter (Collider other)
 {
     if(other.transform.tag == "TriggerCube")
     {
         cubeScript = other.GetComponent<CubeStateScript>();
         if(cubeScript.myColor == transform.tag)
         {
             //award The player with his points
             scoreScript.points = scoreScript.points + maxScore;
         }
         else
         {        
             other.renderer.material.shader = shader2;
             delta = Time.timeSinceLevelLoad;
             other1Gobject = other.gameObject;
             other1Gobject.audio.Play();
             
             other.rigidbody.useGravity = false;
             other1 = other;
             shaderChange = true;
             otherParticle.emit = true;
         }
     }
 }
 
 void Update ()
 {
     if(shaderChange == true)
     {
         other1.renderer.material.SetFloat("_SliceAmount", 0.0f + Mathf.Lerp(0.0f , 1.0f, (Time.timeSinceLevelLoad - delta) *0.5f));
         lightIntensity = other1.light.intensity;
         other1.light.intensity = Mathf.Lerp(lightIntensity , 0.0f, (Time.time - delta) *0.5f);
         
         if(other1.renderer.material.GetFloat("_SliceAmount") == 1.0f)
         {
             other1Gobject.collider.enabled = false;
             other1Gobject.particleEmitter.emit = false;
             
             cubeScript.waitTillIDie = true;
             shaderChange = false;
         }
     }
 }


Thanks

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

1 Reply

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

Answer by whydoidoit · Jun 13, 2012 at 10:15 PM

OnTriggerEnter is called multiple times (once for each collider hit) - it takes a single collider so drop your foreach loop and make the parameter of type Collider.

Comment
Add comment · Show 7 · 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 ragnaros100 · Jun 13, 2012 at 10:30 PM 0
Share

thanks for the answer but it didnt really fix the problem:

when one of the desired gameobjects hits my trigger, it works perfectly and it does what it has to do(the code above is just used as an example for easy read purposes). But when the first gameobject are undergoing its stuff, if I push another gameobject into the trigger. It cancels out the first "stuff-doing" sequence.

So all in all I need to make the script able to handle more than one collition at a time.

Tell me If you need the actual code :)

avatar image whydoidoit · Jun 13, 2012 at 10:32 PM 1
Share

Well that would be helpful :) You have an error in the logic you are using for your processing, because OnTriggerEnter works the way I described...

avatar image ragnaros100 · Jun 13, 2012 at 10:50 PM 0
Share

editted. :)

avatar image whydoidoit · Jun 13, 2012 at 10:51 PM 1
Share

Right so your problem is that you have multiple collisions and only one variable to handle it - the other1 stuff. It would make more sense to have the thing that works on the hit item be on the script of the hit item rather than trying to pull it over into this script.

avatar image ragnaros100 · Jun 13, 2012 at 10:56 PM 0
Share

Oh. I'll try that out. :)...

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How would I find the name of all game objects in a c# List 1 Answer

Distribute terrain in zones 3 Answers

C# For loop in button to set gameObjects in array to active 1 Answer

Array problems 3 Answers

How to assign variables to each GameObject in an array 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