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
-1
Question by doodleasa · May 10, 2016 at 06:03 AM · 2dtransformplayerenemyteleporting

teleportation problems (2d)

i want to make an enemy that when touched teleports the player to x0 y4 zn/a here is what I have: using UnityEngine; using System.Collections;

 public class kill_player : MonoBehaviour
 {
     public GameObject player;
     void OnCollisionEnter(Collision col)
     {
         if (col.gameObject.name == "murder")
         {
             player.transform.position = new Vector2(0, 4);
         }
     }
 }

what makes it not work? and is it not the script?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Highwalker · May 10, 2016 at 06:50 AM

Make sure you have the player variable set in the inspector. Then try this.

 public class kill_player : MonoBehaviour
      {
          public GameObject player;
          void OnCollisionEnter(Collision col)
          {
              if (col.gameObject == player)
              {
                  player.transform.position = new Vector2(0, 4);
              }
          }
      }

Comment
Add comment · Show 16 · 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 doodleasa · May 10, 2016 at 10:18 PM 0
Share

it give this error: the type or namespace name "monobehaviour" could not be found

avatar image doodleasa · May 10, 2016 at 10:26 PM 0
Share

also the script is on the player

avatar image doodleasa · May 10, 2016 at 10:30 PM 0
Share

I derped it works now

avatar image doodleasa doodleasa · May 10, 2016 at 10:39 PM 0
Share

that is there is no error it still doesn't tp you

avatar image Highwalker doodleasa · May 10, 2016 at 10:42 PM 0
Share

Try putting it on your enemy.

Also, is one of your colliders a trigger?

Show more comments
Show more comments
avatar image doodleasa · May 11, 2016 at 03:23 AM 0
Share

2d box colliders

avatar image doodleasa · May 11, 2016 at 03:34 AM 0
Share

"script error: OnCollisionEnter2D This message parameter has to be of type:"

avatar image Highwalker doodleasa · May 11, 2016 at 04:09 AM 0
Share

Okay. Let's start from scratch. Attach a 2D collider to your player and set it as a trigger. Set the enemy's tag to "Enemy". Then attach this script to your player.

 public class PlayerTeleport : $$anonymous$$onoBehaviour
       {
           void OnTriggerEnter2D (Collider2D coll) {
               if (coll.tag == "Enemy") {
                    transform.position = new Vector2 (0, 4); 
               }
           }
       }
avatar image doodleasa Highwalker · May 12, 2016 at 12:21 AM 0
Share

2 problems one somehow it still no work also we need to allow the player to colide with other objects in the sene

Show more comments

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

Unity Enemy Range detection 3 Answers

Enemy follows the only player in rotation 2 Answers

How can I make a collision sensitive teleporter for a 2D game #c 1 Answer

Enemy collider used as range to detect player causes player to not go into jump animation, how should I deal with that? 0 Answers

Teleporting Script Doesn't Work With Anything But The Player 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