- Home /
Trigger event from ground and activate the Object-child in the Camera
EDIT2: I can't seen to get it working, can anybody create a simple script for me? As I told before, I have zero knowledge in scripting... I'm trying to learn.
EDIT: This is what I want to do...
Hello, I'm making a atmospheric terror game, and I need help because I have little knowldge in scripting. I need to pick-up a flashlight from the ground, and I already got this working:
function OnTriggerEnter (myTrigger : Collider) {
if(myTrigger.gameObject.name == "FPSPlayer"){
Debug.Log("Flashlight Found");
}
}
It shows up right in the console, next thing I need is to add the flashlight to the hierarchy on the parent FPSPlayer (I use Ultimate FPS Camera). And make the flashlight on the ground disappear (This should be rather easy to do). Can anybody point me something?
Thanks everybody.
Answer by ThePunisher · Feb 08, 2013 at 05:30 AM
Sounds simple enough. I'm assuming the script I'm looking at is on your flashlight, is it? If so, you could try parenting the flashlight to the player.
Try replacing your debug statement with this:
transform.parent = myTrigger.gameObject.transform;
This should parent the flashlight to your player so that it moves with your player. Now you can just set the transform.localPosition and transform.localRotation to whatever it is you need to get it to look right.
Edit: Oooooh. That's clever. Well, all you have to do then is call Destroy() on the Lantern on the ground, and then enable the one under your camera by using the enabled property.
http://docs.unity3d.com/Documentation/ScriptReference/Behaviour-enabled.html
http://docs.unity3d.com/Documentation/ScriptReference/Object.Destroy.html
This is the way to go. But I might recommend placing a reference transform on your player at the position and rotation that you want your flashlight to be positioned at. This way you place the flashlight where you want in the editor then move the flashlight to the exact position you want it at without a lot of fuss in the code.
Your answer
![](https://koobas.hobune.stream/wayback/20220613092334im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Help with pickup script 0 Answers
help with Flashlight Pickup 1 Answer
Battery Pickup Regeneration 2 Answers