Hello All,
I am a visual artist and have nothing much to do with programming, but i have planned to make a really simple (simple as i tought in the first place lol) video game. the premise of the video game is that you as a pigeon will build a nest from stuff you find on the game.
My problem is very simple: i cannot pick up stuff. I have fallowed a video tutorial (
) and it worked perfectly in 2019 version for the standrad fps controller. Right now im using a 3rd person controller and unit y2020 and it doesnt work.
this is what it reads me:
InvalidOperationException: You are trying to read Input using the UnityEngine.Input class, but you have switched active Input handling to Input System package in Player Settings.
UnityEngine.Input.GetKeyDown (UnityEngine.KeyCode key) (at /Users/bokken/buildslave/unity/build/Modules/InputLegacy/Input.bindings.cs:323)
Pickup.Update () (at Assets/Pickup.cs:18)
here is the code attached below :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Pickup : MonoBehaviour
{
public float pickUpRange=50;
public float moveForce = 250;
public Transform holdParent;
private GameObject heldObj;
// Update is called once per frame
void Update()
{
if(Input.GetKeyDown(KeyCode.E))
{
if(heldObj == null)
{
RaycastHit hit;
if(Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward),out hit, pickUpRange))
{
PickupObject (hit.transform.gameObject);
}
} else
{
DropObject();
}
}
if(heldObj !=null)
{
MoveObject();
}
void MoveObject()
{
if(Vector3.Distance(heldObj.transform.position, holdParent.position) > 0.1f)
{
Vector3 moveDirection = (holdParent.position - heldObj.transform.position);
heldObj.GetComponent<Rigidbody>().AddForce (moveDirection * moveForce);
}
}
}
void PickupObject(GameObject pickObj)
{
if(pickObj.GetComponent <Rigidbody>() )
{
Rigidbody objRig = pickObj.GetComponent<Rigidbody>();
objRig.useGravity = false;
objRig.drag = 10;
objRig.transform.parent = holdParent;
heldObj = pickObj;
}
}
void DropObject ()
{
Rigidbody heldRig = heldObj.GetComponent<Rigidbody>();
heldRig. useGravity = true;
heldRig.drag = 1;
heldObj.transform.parent = null;
heldObj = null;
}
}