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 Lethn · May 18, 2015 at 03:44 PM · publicvoid

The Name RespawnPlayer does not exist in the current context

So I've been working through this series of Unity tutorials by GamesPlusJames and he explains everything clearly, I've occasionally run into problems but usually it's been the result of a typo or I just need to make sure that I've entered in updated code for Unity 5.

For respawning mechanics however I've run into a very annoying problem and none of the usual tricks seem to work so I'm posting this up for you guys to look at, it's pretty self-explanatory code. All he's doing is creating a simple debug message so we can tell whether the player is colliding with an enemy or not.

I get the following error codes:

Assets/KillPlayer.cs(25,40): error CS0103: The name RespawnPlayer' does not exist in the current context Assets/KillPlayer.cs(23,17): error CS0029: Cannot implicitly convert type string' to `bool'

KillPlayer Class

 using UnityEngine;
 using System.Collections;
 
 public class KillPlayer : MonoBehaviour {
     
     public LevelManager levelManager;
     
     // Use this for initialization
     void Start () {
 
         levelManager = FindObjectOfType<LevelManager> ();
         
     }
     
     // Update is called once per frame
     void Update () {
         
     }
     
     void onTriggerEnter2D (Collider2D other)
         
     {
         if (other.name = "Player")
         {
             levelManager = RespawnPlayer();
         }
     }
     
 }

LevelManager Class

 using UnityEngine;
 using System.Collections;
 
 public class LevelManager : MonoBehaviour {
     
     public GameObject currentCheckpoint;
     private PlayerController player;
     
     // Use this for initialization
     void Start () {
         
         player = FindObjectOfType<PlayerController>();
         
     }
     
     // Update is called once per frame
     void Update () {
         
     }
     
     public void RespawnPlayer()
         
     {
         Debug.Log ("Player Respawn");
     }
 }


Hope I've been clear enough with my post, it would be nice if I could have help looking at this conversion error as well but something tells me these problems are usually fixed with one line of code or even a letter rather than being a massive problem.

https://www.youtube.com/watch?v=ndYd4S7UkAU - here's the youtube video itself explaining everything

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
1
Best Answer

Answer by maccabbe · May 18, 2015 at 03:47 PM

If you want to use a method or variable of a class or object use Class.Method, so replace

 levelManager=RespawnPlayer();

with

 levelManager.RespawnPlayer();

Also, as a side note, Unity is case sensitive so onTriggerEnter2D should be OnTriggerEnter2D

Comment
Add comment · Show 4 · 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 Lethn · May 18, 2015 at 04:04 PM 0
Share

Thank you! That immediately fixed the RespawnPlayer issue, as usual it was one lousy out of place character.

The only problem left to fix now is this convert error.

avatar image Lethn · May 18, 2015 at 04:06 PM 0
Share

Just fixed it myself, I was using "=" ins$$anonymous$$d of "==" classic mistake because I didn't watch the video carefully enough, so I should be able to work through everything now.

 level$$anonymous$$anager = RespawnPlayer();
 

should be

 level$$anonymous$$anager == RespawnPlayer();



Thanks for all your help! That got me past a very annoying wall.

avatar image Lethn · May 19, 2015 at 09:00 AM 0
Share

I'm worried about clogging up the board with posts so I'll keep this question in this one since it's all following a specific video. I have just one more line to worry about before everything is completely functional.

I'm getting the following error code:

Assets/Checkpoint.cs(25,38): error CS0120: An object reference is required to access non-static member `Level$$anonymous$$anager.currentCheckpoint'

Checkpoint Class

 using UnityEngine;
 using System.Collections;
 
 public class Checkpoint : $$anonymous$$onoBehaviour {
 
     public Level$$anonymous$$anager level$$anonymous$$anager;
 
     // Use this for initialization
     void Start () {
 
         level$$anonymous$$anager = FindObjectOfType<Level$$anonymous$$anager> ();
     
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 
     void OnTriggerEnter2D (Collider2D other)
         
     {
         if (other.name == "Player")
         {
             Level$$anonymous$$anager.currentCheckpoint = gameObject;
             Debug.Log ("Activated Checkpoint" + transform.position);
         }
     }
 }
 

This is for the very simple checkpoint class the guy demonstrates now I've already tried messing around and replacing "=" with "." and I've tried GameObject. Normally the types of error above just seem to be a complaint about na$$anonymous$$g conventions or the Level$$anonymous$$anager not having a target in the actual inspector window.

However after having checked all of that it seems like something else is going on.

avatar image Lethn · May 23, 2015 at 11:36 AM 0
Share

Sorry, I just thought I'd mention for those who might think to answer this extra question I asked I ended up solving it. Unfortunately I've forgotten how! I'm pretty sure it was a simple case of just double checking my code though.

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

2 People are following this question.

avatar image avatar image

Related Questions

Start a Coroutine in script A, from script B C# 1 Answer

why is my text not changing? [please help] 2 Answers

StartCoroutine in a public static void 1 Answer

SetActive(false) not working 1 Answer

how to activate a public void from another script 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