Ok I give up. The effect I want is for one object (player, 3rd person) to pick up and hold an object and then be able to drop it.
I tried detecting if they are touching, and then when a button is pressed the object is parented to the player object. But I’m going nowhere fast. Any help is appreciated.
My problem now is that I dont know how to reference other objects. I have this code below on the trigger but I dont know how to associate the player and the object. And the same goes for the parenting code.
function Update () {
}
function OnTriggerStay(other : Collider){
if(Input.GetButton("Fire1")){
Destroy(gameObject);
}
}
// For this example, this is a component on the pickup.
// Declare player public so it shows up in the inspector.
// Drag the player onto pickup/player, in the Inspector for the pickup.
// You can now reference it all you want.
public Transform player;
function Update ()
{
}
function OnTriggerStay(other : Collider)
{
if(Input.GetButton("Fire1")){
Destroy(gameObject);
}
player.SendMessage ("YouFiredATrigger", "pickup");
}
I have to point out that this example is a little funky because you could accomplish the same thing by referencing the “other” variable in the function. ( if (other.tag = “Player”) … )
I have a trigger cube parented to my object mesh (object > trigger) and I want to delete the entire instance (parent and child) when the cube is triggered.
There is whole bunch of different ways to accomplish that. Here’s one.
public class bump_delete : MonoBehaviour {
/*
* This attaches to trigger
* The trigger and the box are in the same directory.
* Here is an example of Walking into the trigger, picks up box.
* Walk back into trigger, it deletes the box.
*
*/
public Transform box;
public bool hasBox = false;
void OnTriggerEnter(Collider player) {
if (!hasBox){
hasBox = true;
box.transform.parent = player.transform;
}else{
Destroy(box.gameObject, 5);
}
}
}
Thanks for the help, but I just cant seem to combine what you gave with what I have. Also Im getting a lot of errors with your code. Im using JavaScript, is that C#?
Here’s what I’m trying to accomplish. The player has a box parented to his chest that turns its renderer on and off. There is a cube object on the ground with a trigger parented to it. When the player enters the trigger space and presses “q”, the cube on the ground is destroyed and the cube on the chest is rendered. Then when the player presses “e”, the chest cube is derendered and a new cube is instantiated in its place.
This is the script on the chest cube.
var dropBox : Transform;
function Update () {
if(Input.GetKeyDown("q")){
renderer.enabled=true;
}
if(Input.GetKeyDown("e")){
renderer.enabled=false;
boxtemp = Instantiate(dropBox, transform.position, transform.rotation);
}
}
This is the script on the trigger of the other cube. Right it just deletes itself, but I want it to delete the cube that it is parented to.
function Update () {
}
function OnTriggerStay(other:Collider){
if(Input.GetKeyDown("q")){
Destroy(gameObject);
}
}
Hey I have added 2 Script to Complete a full Grab toggle and ready to move code,
all you have to do is add the movements in you want to the ObjectReplyIdAndMove script and add some conditions for the overides in the Main player Script ObjectGrabIdAndMove if u want to move the object out of center view… currently when object is selected its not told to move but is ready too.
ObjectGrabIdAndMove goes on Main player,… ObjectReplyIdAndMove goes on Moveable Objects rember to add layers in you want to hit
Hey I have added 2 Script to Complete a full Grab toggle and ready to move code,
all you have to do is add the movements in you want to the ObjectReplyIdAndMove script and add some conditions for the overides in the Main player Script ObjectGrabIdAndMove if u want to move the object out of center view… currently when object is selected its not told to move but is ready too.
ObjectGrabIdAndMove goes on Main player,… ObjectReplyIdAndMove goes on Moveable Objects rember to add layers in you want to hit
ReCompiled Scripts Alomst Finished bar Diagnals and mouse rotation defualt is working with full inversion raycast linecast ID check Ect ect its all there Enjoy. ill be finishing the Mouse rotations over the week took lopng enough to get this far.
I was trying to figure out my error, however I still cant figure out why my PickUP object wont convert or become the child of my Player. It wont become the object held so it just remains in the same place although I have pressed the button. Any suggestions to get it to work?