Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 mgamall · Jun 22, 2011 at 05:11 PM · gameobjectvariableruntimeassign

How can I assign a GameObject to a variable at runtime?

how to change the game object in the run time??? is it hard listen this


  var targer = GameObject"

how can i change the game object in the run time

lets say
i am the camera and i shot a bullet toward a cube when it hit it i want it to put the cube In the game object on the run time

or to hit it with the ray cast instead of bullet. i hope u got it....

Comment
Add comment · Show 8
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 Chris D · Jun 22, 2011 at 05:18 PM 0
Share

Ok, we're going to need some clarification here. Are you asking how to 'shoot' a game object and then place the object that's hit into a variable?

avatar image mgamall · Jun 22, 2011 at 05:24 PM 0
Share

something like that

avatar image mgamall · Jun 22, 2011 at 05:26 PM 0
Share

its to make a targeting system to a plane aim with camera when i aim at at target it put it in the gameobject variable

avatar image mgamall · Jun 22, 2011 at 05:34 PM 0
Share

i got an idea for it. look i made a gun script! i will put it in the camera and make it shoot all the time and when it hit something it change the variable gameObject in the ho$$anonymous$$g missile script (The $$anonymous$$issile Target). i shoot It chase it and going down.

if u could make it with raycast it would be better..

avatar image Chris D · Jun 22, 2011 at 05:38 PM 0
Share

Please try to form sentences. It's hard enough to understand exactly what's going on without having to parse your words manually, too.

Are you saying you've fixed your problem?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Chris D · Jun 22, 2011 at 05:52 PM

You should look at the Raycast functions available. All you need to do is raycast from the camera's transform.position to where your mouse/selector/whatever is currently on.

Search through the other raycast questions on the site for a very complete listing of different approaches. Search terms include 'mouse click', 'raycast', 'select' etc.

Once you successfully raycast to something, you use the RaycastHit information to reference the object that's hit.

 var whatYouHit = RaycastHit.rigidbody.gameObject;


Comment
Add comment · Show 2 · 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 darkhero · Jul 01, 2011 at 10:38 PM 0
Share

hay am new here how to do that can u make an example

avatar image Chris D · Jul 04, 2011 at 04:26 PM 0
Share

If you don't understand how to do what I've mentioned above, try going through some of the tutorials (I believe there's some raycasting going on in the FPS tutorial) and then looking at the manual on the Unity site.

If you're still stuck, come back to this site and create a new question about your specific problem.

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

Remove object assignment in runtime? 1 Answer

Store a GameObject to a variable on runtime. 1 Answer

is there a way to assign north south to an object? 2 Answers

Assign a gameobject in a scene to a varible automatically? 0 Answers

Keeping old GameObject values 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