C
C#3mo ago
moonbat

Player death script(fixed)

I cant seem to make it work at all. No matter how I try to fix it or use someone elses code it simply will not work. my Text editer says there is no issues. Ive tried like 4 different videos, chat gpt, and just looking around. My unity project isnt anything fancy either. Its just 4 walls, a player with a basic jump script and thats it.
No description
12 Replies
moonbat
moonbatOP3mo ago
this is the error I keep getting in unity
Tracer
Tracer3mo ago
Can you show your code?
moonbat
moonbatOP3mo ago
yea gimme one sec to open it back up is there a better way to send it?
Tracer
Tracer3mo ago
please format your code: ```cs code ```
moonbat
moonbatOP3mo ago
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Killplayer : MonoBehaviour
{
public GameObject Player;
public Transform respawnPoint;

void Start()
{y

}

void Update()
{

}

private void OnCollisionEnter2D(Collision2D other)
{
if(other.gameObject.CompareTag("Player"))
{
Player.transform.position = respawnPoint.position;

}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Killplayer : MonoBehaviour
{
public GameObject Player;
public Transform respawnPoint;

void Start()
{y

}

void Update()
{

}

private void OnCollisionEnter2D(Collision2D other)
{
if(other.gameObject.CompareTag("Player"))
{
Player.transform.position = respawnPoint.position;

}
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Net.Http.Headers;
using System.Numerics;
using Unity.Burst.Intrinsics;
using Unity.VisualScripting;
using UnityEditor.Callbacks;
using UnityEngine;
using Vector2 = UnityEngine.Vector2;

public class PlayerMovementScript : MonoBehaviour
{

public float Jump;
public Rigidbody2D rb;

private Collider2D _collider;

private bool _active = true;


// Start is called before the first frame update
void Start()
{
_collider = GetComponent<Collider2D>();
}

// Update is called once per frame
void Update()
{
if(Input.GetButtonDown("Jump"))
{
rb.velocity = new Vector2(rb.velocity.x,0);

rb.AddForce(new Vector2(0, Jump));
}
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Net.Http.Headers;
using System.Numerics;
using Unity.Burst.Intrinsics;
using Unity.VisualScripting;
using UnityEditor.Callbacks;
using UnityEngine;
using Vector2 = UnityEngine.Vector2;

public class PlayerMovementScript : MonoBehaviour
{

public float Jump;
public Rigidbody2D rb;

private Collider2D _collider;

private bool _active = true;


// Start is called before the first frame update
void Start()
{
_collider = GetComponent<Collider2D>();
}

// Update is called once per frame
void Update()
{
if(Input.GetButtonDown("Jump"))
{
rb.velocity = new Vector2(rb.velocity.x,0);

rb.AddForce(new Vector2(0, Jump));
}
}
}
Tracer
Tracer3mo ago
Did you assign the Player variable? From the editor I mean as you dont initialize it anywhere in your code
moonbat
moonbatOP3mo ago
this one right?
No description
Tracer
Tracer3mo ago
Yup
moonbat
moonbatOP3mo ago
yea they are all conected but i get the same issue yea kill play.cs
Keswiik
Keswiik3mo ago
sounds like you haven't assigned the player tag in the editor
Anton
Anton3mo ago
use layers for this rather than tags if you can
moonbat
moonbatOP3mo ago
I finally got it to work thank you. I just had to put the player tag on the player game object

Did you find this page helpful?