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 Decoy_1207 · Mar 28, 2014 at 01:12 AM · 2djavascriptcolliderteleport

Issue with my Teleport Script

I'm trying to make a script that will allow me to click on a Collider (with mouse button) that will destroy my player and create it in another location. (using a prefab of the player)

The current script i have is based of 2 seperate scripts (that work fine). One is an push the button and the elevator goes up or down. The other is my Killzone for when players fall down the level and it will respawn them at the start of the level.

 #pragma strict
 
 private var pressedButton : boolean = false;
 private var teleportup : boolean = false;
 
 var Player : GameObject;
 var location2 : Transform;
 
 
 function OnTriggerEnter2D(other : Collider2D){
 pressedButton = true;
 }
 
 function OnTriggerExit2D(other : Collider2D){
 pressedButton = false;
 }
 
 function OnMouseDown(){
     if(teleportup == true){
         Destroy(other.gameObject);
         var P : GameObject = Instantiate(Player, location2.position, Quaternion.identity);
     }
     
 }
 function OnGUI()
 {
     if(pressedButton == true){
         GUI.Box(new Rect(300,300,200,20), "Click to Activate!");
         }
     }

The error i'm currently getting is: teleporter.js(20,25): BCE0005: Unknown identifier: 'other'.

I've tried adding function OnMouseDown(other : Collider2D), trying to identify the "other" but that doesn't seem to work. It allows me to go ingame with that though, but when i click on the collider i get the following error:

Failed to call function OnMouseDown of class click teleporter Calling function OnMouseDown with no parameters but the function requires 1. UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32, Int32)

My knowledge of programming is limited and i have alot of learning ahead of me, so any help would be appriciated.

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 supernat · Mar 28, 2014 at 01:17 AM

On line 20, if you want to destroy the player, it would be

 Destroy(Player);

This is a function scope issue. The variable "other" doesn't exist in the function. The method OnMouseDown() is not your own method. You are overriding the method from a base class, so you can't just change what gets passed to it. When you change the function parameters, it becomes a different, unique, function. I would recommend brushing up on some programming basics online that will cover these. I like lynda.com myself, great videos there. Good luck.

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

21 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Big noob Need to know how I can make that 1 Answer

Collision with renderer.enabled? 0 Answers

Creation of Edge Colliders at Runtime 0 Answers

Take boolean from other script error 1 Answer

Script doesn't find other script 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