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 Lucas · Nov 01, 2010 at 07:58 PM · colliderontriggerenterraycasthit

The problems of Collider ....

I built a laser tower to attack enemies.

Tower Code :

var hit : RaycastHit;
Physics.Raycast(Vector3(transform.position.x, transform.position.y + 2, transform.position.z), transform.forward, hit , attackingRange);
if (hit.collider)
{
lineRenderer.SetPosition(1,Vector3(0,0,Mathf.Sqrt(attackingRange)));
print(hit.collider.gameObject.tag);
}

I can get the hit.collider.gameObject.tag is Enemy.

Enemy Code :

function OnTriggerEnter( hit : Collider)
{
  print(hit.gameObject.tag);
}

get nothing.........

why why why....??? anyone can help me??

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
1
Best Answer

Answer by Mike 3 · Nov 01, 2010 at 09:05 PM

Raycasts don't cause collisions if that's what you're getting at

If you need to tell the enemy code to do something, try using SendMessage instead, or possibly GetComponent and then call a function

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 Lucas · Nov 02, 2010 at 02:30 AM 0
Share

Hi, $$anonymous$$ike. You can check my another question, I tried to use Send$$anonymous$$essage or GetComponent to solve this problem. (http://answers.unity3d.com/questions/25796/a-problem-about-broadcastmessage-and-getcomponent-please-help-me) Please help me~~~ tell me how to do ...

avatar image Lucas · Nov 02, 2010 at 02:33 AM 0
Share

Dear $$anonymous$$ike, I used GetComponent, the error is "NullReferenceException: Object reference not set to an instance of an object". Then I tried Broadcast$$anonymous$$essage/Send$$anonymous$$essage, I got "Broadcast$$anonymous$$essage Energy has no receiver!"..

avatar image Mike 3 · Nov 02, 2010 at 11:28 AM 0
Share

The problem is probably because you're doing it no matter what you hit. Try Send$$anonymous$$essage("FunctionName", Send$$anonymous$$essageOptions.DontRequireReceiver); if you don't want to check the tag before doing Send$$anonymous$$essage

avatar image Lucas · Nov 03, 2010 at 06:51 AM 0
Share

Dear $$anonymous$$ike, I used Send$$anonymous$$essage("Energy", Send$$anonymous$$essageOptions.DontRequireReceiver); when enemies' HP <= 0. Then, I wrote a function Energy (){ print(energyValue); } in Vortex tower script and get nothing, I'm sure there is a vortex tower in the scene. How could I do ?

avatar image Mike 3 · Nov 03, 2010 at 08:45 AM 0
Share

hit.gameObject.Send$$anonymous$$essage("Energy", Send$$anonymous$$essageOptions.DontRequireReceiver); is probably what you want, so it sends it to the object that is hit

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

No one has followed this question yet.

Related Questions

BoxCollider Overlap OnTriggerEnter Problem 1 Answer

Collision Checking 1 Answer

How to make player go through object but can't go back 3 Answers

Can't figure out how to use multiple triggers in single scene 1 Answer

Box collider doesn't work when same size as mesh. 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