Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Trouch · Feb 04, 2013 at 02:27 PM · gameobjecttransformnoobnewbie

Change gameObject within a Transfom

Hi guys, sorry if this is hard to explain.

I have the following code

  var checkpoint : Transform;
  var checkpoint2 : GameObject; 
  function Awake () {
      transform.position = checkpoint.position;
      transform.rotation = checkpoint.rotation;
  }

checkpoint is a spawn location, within my game. i have to manually add the prefab/empty object as the spawn location (click and drag into the variable box).

I would like to automatically change that variable, with a different prefab/empty object. This would allow a new spawn location, where ever the new/second prefab is located.

Problem is, you cant Mix a gameobject with a transform. How can i overcome this?

Surely if i can manually add a prefab into the variable, i should be able to change that variable with another prefab, automatically.

Thankyou

Edit: I would like to make "checkpoint2" the new variable within "Checkpoint"

Comment
Add comment · Show 3
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 Wolfram · Feb 04, 2013 at 02:36 PM 1
Share

Do you want to assign a GameObject to checkpoint2 in the Inspector in the Editor, or dynamically at runtime during your game?

Also note: checkpoint.gameObject is the associated GO, checkpoint2.transform is the associateed Transform.

avatar image Trouch · Feb 04, 2013 at 02:38 PM 0
Share

Dynamically. So you spawn at checkpoint - Spawn 1 Load a new scene + change checkpoint to Spawn 2 Return to previous scene and checkpoint now = spawn 2, where you spawn into.

avatar image Trouch · Feb 04, 2013 at 02:42 PM 0
Share

I think T27$$anonymous$$ might of solved it for me. thanks anyways :)

1 Reply

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

Answer by T27M · Feb 04, 2013 at 02:36 PM

You can get the transform of the gameobject with

 transform.position = checkpoint2.transform.position;
Comment
Add comment · Show 3 · 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 Trouch · Feb 04, 2013 at 02:41 PM 0
Share

Ah! I think this is what im missing. I came really close to typing that. but i think i did checkpoint2.position.transform;

It worked. Thankyou! (Now i just gotta figure out if i can use it the way i want to, i think i should be able to, thanks again!)

avatar image T27M · Feb 04, 2013 at 02:45 PM 0
Share

How many checkpoints are you planning on having? If you want to store many I would store all the potential checkpoints in a list or array and set them based on the `Application.loadedLevelName("levelName");

If you are only going to have one checkpoint per level you could tag it and search for that checkpoint after the level has loaded.

There's quite a few ways you could set them dynamically, it depends on the result you're ai$$anonymous$$g for.

avatar image Trouch · Feb 04, 2013 at 03:09 PM 0
Share

Not too sure right now. Probably many, but 4-7 per scene only.

Its for entering and exiting. If i enter a house, then exit. i want to spawn outside the door, not at 0,0,0.

Right now i have a string setup, when i trigger a door (load.level) it changes the string to something such as "Spawn2" and when i exit, i want the character to now spawn at "Spawn2".

Playing around with it now, trying to get it working with what you provided initially.

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

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Keep adding targets to a list 2 Answers

Rotating a Vector3 in Instantiation 1 Answer

Calculating mesh over GameObject scale 1 Answer

Generating a Displacement Map in Unity3d? 1 Answer

Change target after destroying it. 2 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