- Home /
Respawn Point dont work, is because is a prefab?
Hi everyone, i am a beginner in unity. And i have a trouble with my respawn point. When my player (prefab) have 0 or less HP, die. But the problem is the "player1.transform.position = respawnPoint1.position;" code dont work, but the nexts yes. The HP bar go to 100 but the position of the player dont change. I dont know how to repare dat. Sorry for my bad english :,(
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RespawnPlayers : MonoBehaviour
{
[SerializeField]Transform player1;
[SerializeField]Transform respawnPoint1;
private HealthBar healthbar;
public void hasMuerto()
{
player1.transform.position = respawnPoint1.position;
healthbar = FindObjectOfType<HealthBar>();
healthbar.respawnMaxHealth();
}
}
Answer by Magso · Jul 01, 2020 at 02:53 PM
You have player1.transform.position
but player1
is already a transform so it should be player1.position
. Also (I don't know if it's the same in newer unity versions) but if you were using a CharacterController you couldn't set it's position directly.
Thanks for respond me. Yes, i am using a CharacterController. How can i change the position if i have a CharacterController?
Answer by simonck8000 · Jul 01, 2020 at 03:35 PM
Fixed, need to go "Proyects Settings" > "Physics" and turn on "Auto Sync Transforms"
Your answer
Follow this Question
Related Questions
Error while creating an object 0 Answers
How do I make my projectile deal damage to a target it hit. 1 Answer
Rocket Projectiles in Flight Simulator error 1 Answer
How do I make do I make a variable go back to its original value for a spell system 1 Answer
Trying to setbool of animator from another object c# 1 Answer