I am making a project where the character is trying to pick up a sword from a chest. I am using a raycast to gauge the distance from the character to the sword- when the character hits E, or “Input”, the sword in the chest should disappear and reappear in their hand. But this is not the case for my script. My sword will disappear in the chest, the reappear moments later- but the sword does not appear in their hand. Any help is greatly appreciated!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Grabweapon : MonoBehaviour {
public GameObject FakeSword;
public GameObject RealSword;
private float TheDistance;
// Use this for initialization
void Start () {
RealSword.SetActive(false);
}
// Update is called once per frame
void Update () {
TheDistance = PlayerRaycast.DistanceFromTarget;
if (TheDistance <= 3) {
if(Input.GetButtonDown("Input"));
RealSword.SetActive(true);
}
}
}