I was making a simple script for picking and putting down an object by getting close to a pick up and drop zone area in a game.
In this game my player object is a pick up car. And I tried to make a sphere as pickable object.
In both this videos you will see how I do it:
And here is the script used in these videos, I call it PickableObject.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PickableObject : MonoBehaviour
{
public GameObject PickUpCarBack;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void OnTriggerEnter(Collider col){
if(col.gameObject.name == "PickUpCarSensor"){
transform.position = PickUpCarBack.transform.position;
transform.parent = PickUpCarBack.transform;
}
if(col.gameObject.name == "DropZone"){
GameObject DropPoint = col.gameObject.transform.Find("DropPoint").gameObject;
transform.position = DropPoint.transform.position;
transform.parent = DropPoint.transform;
}
}
}
loading...