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 CommitteeWind · Oct 26, 2010 at 03:17 AM · raycasthitmessagesend

SendMessage and RaycastHit

I am setting up a selection system like one you might see in an RTS game. Having said that, I have a slection script to be placed on every selectable prefab/gameobject. Inside this script i have a function SetSelect().

What I am trying to do is raycast to the object, then call that object's SetSelect function.

Shouldn't I be able to say:

GameObject myObj = rayCastHitInfo.collider.gameObject;
myObj.SendMessage("SetSelect", SendMessageOptions.DontRequireReceiver);

I would THINK so. Maybe I'm thinking all wrong. Anyway it doesn't call the function. I'm not sure why.

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

2 Replies

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

Answer by lhk · Nov 01, 2010 at 07:37 PM

Before you can access the raycasthitinfo object you need to actually cast a ray. Your script needs some more lines

RaycastHit rayCastHitInfo;
if(Physics.Raycast(origin,direction,rayCastHitInfo))
{
    //here comes your code
}

Read the scripting reference for futher information.

Comment
Add comment · 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
1

Answer by skovacs1 · Nov 01, 2010 at 07:37 PM

It may have to do with when or how you are getting your GameObject or when or where you are calling the functions or even just how you're testing whether the function is being called. Without more information like a more complete section of script, it is impossible to guess.

I just tested this setup and it works:

CameraPicker.js

var hit : RaycastHit;

function Update() { if(Input.GetMouseButtonUp(0) && Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition),hit)) { hit.collider.gameObject.SendMessage("Test"); } }

Selectable.js

function Test () {
    Debug.Log(gameObject.name);
}

If this does not address your issue, please include more information as it is likely some other part of your script that is not behaving as you expect.

Comment
Add comment · 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

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

SendMessage , how can i send two parameter 3 Answers

Send Message Has no Receiver 1 Answer

How to Send Message to other GameObject 3 Answers

BroadcastMessage 1 Answer

Flame Thrower - Particle Collision Help 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