r/UnityHelp • u/[deleted] • 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
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. :)