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 Matthew Dennis · May 11, 2011 at 03:33 PM · prefabobjectspawnmove

Updating prefab information live

How can you update a prefabs position values live if it is already in game view?

For example, if i have a prefab of a cube and its XYZ position values are all set at 1. And if i place that prefab into the scene view, but its position values are being set all at 5 and its following way points. If i spawn an object into the game(via mouse click) and i want it to follow that cube, it will always go to the prefab coor'ds, meaning 1. How can i change that value so the cude will actually move towards it?

EDIT:

Here is what i am doing at the moment:

var target : Transform; var smooth = 5.0;

function Update() { transform.position = Vector3.Lerp(transform.position, target.position, Time.deltaTime * smooth);

}

Explanation: When my Player gameObject hits an enemy collider (which is bigger than the enemy gameObject) this script will be activated so a prefab(which is just a square at the moment) will 'fire' at the enemy target to destroy it.

Comment
Add comment · Show 1
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 DaveA · May 11, 2011 at 11:03 PM 0
Share

Can you post some code?

2 Replies

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

Answer by DaveA · May 11, 2011 at 11:05 PM

Assuming you're doing something like the samples here: http://unity3d.com/support/documentation/ScriptReference/Object.Instantiate.html

You would have something like (from that page)

var clone : Rigidbody;

clone = Instantiate(projectile, transform.position, transform.rotation); clone.transform.position = whereever you want it

and use 'clone' in your Update script to set its transform.position to follow the cube

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
0

Answer by Bryan 4 · May 11, 2011 at 03:53 PM

It appears your spawned object are referencing the prefab itself and not the cube in game. On your object spawn you should have it just pull a reference to the thing you want it to follow in game. That will ensure it follows the correct object.

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

The appearance of some prefab appears somewhere else but their collider stays in the good place, that to make? 0 Answers

How do I move a Prefab toward a freshly spawned Prefab? 1 Answer

Spawning objects help 2 Answers

What should a script contain? 1 Answer

How to Use Object Pooling for a 3D Autorunner? As Opposed to Instantiate? 0 Answers


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