r/UnityHelp • • May 28 '21

Code for picking up object wont work.

I am new to c# so sorry if its obvious, but I have it so if you walk over a headlamp it will be teleported onto your head. by having a trigger on the helmet and the destination a child to the player. but nothing happens when you do that. Heres the code:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class Teleporting : MonoBehaviour {

public Transform teleportTarget;

public GameObject theHelmet;

public GameObject thePlayer;

void OnTriggerEnter(Collider thePlayer)

{

theHelmet.transform.position = thePlayer.transform.position;

}

}

4 Upvotes

3 comments sorted by

2

u/Stretchyfish May 28 '21

I think more information is nedded. Does both object have a colliders? Are both colliders set to Trigger? Does either the player or lamp have a RigidBody? But one thing I am noticing is that both the gameObject and collider in OnTrigger is called thePlayer. :D

I can recommend inserting a Debug.Log("test") just to ensure the OnTrigger actually activates when you hit it. :)

1

u/[deleted] Jun 18 '21

theplayer not a mistake no help i got it to work you did not help me remember that i accomplished this without your help you did not help

1

u/[deleted] Mar 14 '22

sorry for going off dont know what was up with me thanks for helping