I want to make a game where the player is a helicopter and there is a small flat sphere under the player.
If it collides with a “Crate”, it carries it by setting the sphere as the parent for the “Crate”.
But how do you release it? I want to hit the Y key and the object fall.
It does not fall however. It still follows and remains a child of the sphere.
This is what I am doing currently:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class extendPickup : MonoBehaviour
{
public GameObject gameobject;
public GameObject homePosition;
public GameObject deployPosition;
bool release = false;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.G) == true)
{
transform.position = Vector3.MoveTowards(transform.position, deployPosition.transform.position, .1f);
}
else if (Input.GetKey(KeyCode.T) == true)
transform.position = Vector3.MoveTowards(transform.position, homePosition.transform.position, .1f);
if (transform.position == deployPosition.transform.position)
transform.localScale = deployPosition.transform.localScale;
else
transform.localScale = homePosition.transform.localScale;
if (Input.GetKeyDown(KeyCode.Y) == true)
release = true;
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Grabable")
{
if (release == false)
{
other.gameObject.transform.parent = transform;
}
if (release == true)
other.gameObject.transform.parent = null;
}
}
}