- Home /
Question by
Pogrammer88 · Mar 16, 2021 at 10:58 PM ·
teleport
Unity Isn't Finding An Object Even Though I Did transform.Find("")
I was making a teleport script for when a player dies or gets knocked out of the map but it keeps erroring out at line 48 for some reason, I added the debug.log for bug testing purposes and it WAS having problem looking for the transform fsr.
public class RoomBounds : MonoBehaviour
{
public Transform RespawnPoint;
public Transform LobbyPoint;
public GameObject photonPlayer;
private PhotonView PV;
public Transform boundCheck;
public LayerMask boundMask;
public float boundDistance = 0.4f;
bool isOutBound;
void Start()
{
LobbyPoint = transform.Find("Spawn");
RespawnPoint = transform.Find("RespawnPoint");
PV = GetComponent<PhotonView>();
}
// Update is called once per frame
void Update()
{
isOutBound = Physics.CheckSphere(boundCheck.position, boundDistance, boundMask);
if (isOutBound)
{
Debug.Log("why am I not being tp'd");
Die();
}
}
[PunRPC]
void Die()
{
photonPlayer.transform.position = RespawnPoint.transform.position;
}
}
Comment
transform.Find
looks for a direct child of this gameObject.
I highly advise you to remove those lines and simply drag & drop the correct gameObjects in the public fields of the inspector.
where is line 48? Use just Find, not transform.Find.
Your answer
Follow this Question
Related Questions
Spawning System 1 Answer
Touch teleport script isnt working 2 Answers
Mirror a Vector3 1 Answer
Velocity not resetting to zero? 1 Answer