• 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 garciapablo1959 · Mar 16, 2017 at 08:27 PM · getcomponent

How to transform.position on a different GameObject with OnTriggerEnter()

Hey. Well, I've googled thru a lot of questsions, tried to do some heavy research in the documentation, watched some videos, but I'm not yet able to make this work on my own (and I don't want to copy/paste scripts from Google :P). It's quite simple. All this script needs to do is: when the player enters on this respawn zone, then he shall be moved to his original position. The scripts enters the "if" structure correctly (tested with print() function), but then I'm out of ideas respecting "getting" the player so I can transform his position and rotation. Please, send help. The script is attached to the respawn zone, not to the player. Notes: My Main_player GameObject is actually the Standard Assets third person white folk. It has a Rigibody enabled and it's not kinematic. My respawn zone it's neither kinematic (actually, it's just a box, but rezised and only attached with the Transform, the Box Collider and the RespawnZone script).

Thanks you in advance.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class RespawnTrigger: MonoBehaviour {
     
 private bool PlayerFound;
 
     void OnTriggerEnter(Collider other) {
         
         print ("Player just fell on " + gameObject);
         PlayerFound = GameObject.Find("Main_player");
 
         if (PlayerFound == true) {
 
           SOME_WAY_OF_GETTING_THE_PLAYER.transform.position = new Vector3(13.5f,0.15f, 0);
           SOME_WAY_OF_GETTING_THE_PLAYER.transform.Rotate = new Vector3 (0, -90, 0);

             print ("Player was moved to his original position.");
         }
     }
 }

EDIT: Solved. The solution that I found out was to read this link carefully: Link

See you later.

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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Accessing other objects efficiently 1 Answer

Destroy(GetComponent(...)) not working 1 Answer

GetComponent(); in Awake cant be accessed in Update 1 Answer

BCW0012: WARNING: 'UnityEngine.MeshCollider.mesh' is obsolete. mesh has been replaced with sharedMesh and will be deprecated 1 Answer

Problem getting information out of colliding objects 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