Unity: Thorwable objects with interact key
This commit is contained in:
parent
080f9a3428
commit
94b71fc610
@ -483,6 +483,14 @@ MonoBehaviour:
|
||||
jumpForce: 2.5
|
||||
gravity: 9.8
|
||||
throwForce: {fileID: 765999536}
|
||||
controller: {fileID: 0}
|
||||
moveDirection: {x: 0, y: 0, z: 0}
|
||||
forwardsKey: 119
|
||||
backwardsKey: 115
|
||||
leftKey: 97
|
||||
rightKey: 101
|
||||
sprintKey: 304
|
||||
jumpKey: 32
|
||||
--- !u!114 &765999536
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -499,7 +507,10 @@ MonoBehaviour:
|
||||
insideTrigger: 0
|
||||
carrying: 0
|
||||
carriableObject: {fileID: 0}
|
||||
previousObject: {fileID: 0}
|
||||
tempObject: {fileID: 0}
|
||||
throwForce: 5
|
||||
interactKey: 102
|
||||
--- !u!1 &876529135
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
8
Assets/Scripts.meta
Normal file
8
Assets/Scripts.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f461b3b4173c411449b3187f57a38c7e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
public class PickUpObject : MonoBehaviour
|
||||
@ -10,8 +12,9 @@ public class PickUpObject : MonoBehaviour
|
||||
public bool insideTrigger = false;
|
||||
public bool carrying = false;
|
||||
public GameObject carriableObject;
|
||||
public GameObject previousObject;
|
||||
public GameObject tempObject;
|
||||
public float throwForce;
|
||||
public KeyCode interactKey = KeyCode.F;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
@ -21,13 +24,24 @@ public class PickUpObject : MonoBehaviour
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if(insideTrigger && Input.GetKeyDown(interactKey) && !carrying)
|
||||
if(tempObject != carriableObject)
|
||||
{
|
||||
previousObject = tempObject;
|
||||
tempObject = carriableObject;
|
||||
previousObject.GetComponent<Rigidbody>().isKinematic = false;
|
||||
}
|
||||
if(insideTrigger && Input.GetKeyDown(KeyCode.F) && !carrying)
|
||||
{
|
||||
carrying = true;
|
||||
carriableObject.GetComponent<Rigidbody>().isKinematic = true;
|
||||
if(tempObject == null)
|
||||
{
|
||||
tempObject = carriableObject;
|
||||
}
|
||||
}
|
||||
else if(carrying && Input.GetKeyDown(interactKey))
|
||||
else if(carrying && Input.GetKeyDown(KeyCode.F))
|
||||
{
|
||||
tempObject = carriableObject;
|
||||
carrying = false;
|
||||
carriableObject.GetComponent<Rigidbody>().isKinematic = false;
|
||||
// Drop the object in the direction the player is moving and add a force to it depending on speed
|
||||
|
Loading…
Reference in New Issue
Block a user