using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class KillPlayer : MonoBehaviour
{
public int Respawn;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnTrigger2D(Collider2D other)
{
if(other.CompareTag("Player"))
{
SceneManager.LoadScene(Respawn);
}
}
}
This was the code that I used. I can’t figure out the problem with it. I am trying to make a simple platformer. I am also new to Unity so don’t laugh at my code.
Explaining what your trying to do would be a great way to start!
Firstly, looking at your code, you made a int called Respawn, then In your OnTrigger2D function, you did SceneManager.LoadScene(Respawn). This is NOT how you use it, read this (https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadScene.html)
Furthermore you should start with tutorials, It’ll be a great way to start
https://www.youtube.com/watch?v=IlKaB1etrik
https://www.youtube.com/watch?v=OR0e-1UBEOU
1 Like
Go grab the docs and check this name too… this is not the name of the function. There’s many variants and they must be spelled EXACTLY the right way.
Visual Studio should be helping you do this with code completion suggestions.
You might need to configure intellisense properly.
This may help you with intellisense and possibly other Visual Studio integration problems:
Sometimes the fix is as simple as doing Assets → Open C# Project from Unity. Other times it requires more.
https://discussions.unity.com/t/778503
Also, try update the VSCode package inside of Unity: Window → Package Manager → Search for Visual Studio Code Editor → Press the Update button
Also, this: https://discussions.unity.com/t/805330/7
Thank you very much for the help!