Witam. Chciałbym dowiedzieć się jak zmienić przypisanie obiektu. Napisałem skrypt który przypisuje Obiekt "Deagle: do Kamery("Camera"),ale brakuje mi wiedzy jak przypisać obiekt w odpowiednie miejsce o nazwie " Weapon Holder".
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PickUp : MonoBehaviour
{
public float Distance = 10f;
public Transform EquipPosition;
GameObject CurrentGun;
public bool CanGrabIt;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
CheckGrab();
if(CanGrabIt)
{
if (Input.GetKeyDown(KeyCode.E))
PickUpObject();
}
}
private void CheckGrab()
{
RaycastHit Hit;
if(Physics.Raycast(transform.position,transform.forward,out Hit,Distance))
{
if (Hit.transform.tag == "CanGrabIt")
{
Debug.Log("CAN GRAB");
CurrentGun = Hit.transform.gameObject;
CanGrabIt = true;
}
}
else
CanGrabIt = false;
}
private void PickUpObject()
{
CurrentGun.transform.position = EquipPosition.position;
CurrentGun.transform.parent = EquipPosition;
CurrentGun.transform.localEulerAngles = new Vector3(0f, 100f, 100f);
CurrentGun.GetComponent<Rigidbody>().isKinematic = true;
Debug.Log(" GRAB");
}
}