mirror of
https://github.com/Project-Redacted/project-hampter.git
synced 2025-06-07 11:13:14 +00:00
Update :3
This commit is contained in:
parent
1f50b3f262
commit
6bbd56a5cf
759 changed files with 269694 additions and 37600 deletions
66
Assets/Scripts/ObjectGrab.cs
Normal file
66
Assets/Scripts/ObjectGrab.cs
Normal file
|
@ -0,0 +1,66 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ObjectGrab : MonoBehaviour
|
||||
{
|
||||
private Rigidbody objectRigidbody;
|
||||
private Transform objectGrabPointTransform;
|
||||
public float ThrowForce = 5;
|
||||
|
||||
private Vector3 StartPosition;
|
||||
private void Awake()
|
||||
{
|
||||
objectRigidbody = GetComponent<Rigidbody>();
|
||||
StartPosition = transform.position;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if(transform.position.y < -5)
|
||||
{
|
||||
ResetPosition();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Grab(Transform objectGrabPointTransform)
|
||||
{
|
||||
//this.objectGrabPointTransform = objectGrabPointTransform;
|
||||
this.transform.parent = objectGrabPointTransform;
|
||||
this.transform.localPosition = new Vector3(0, 0, 0);
|
||||
|
||||
objectRigidbody.useGravity = false;
|
||||
objectRigidbody.isKinematic = true;
|
||||
this.GetComponent<Collider>().enabled = false;
|
||||
Move m = GetComponentInChildren<Move>();
|
||||
if(m != null)
|
||||
{
|
||||
m.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Throw(Vector3 direcction)
|
||||
{
|
||||
this.transform.parent = null;
|
||||
objectRigidbody.useGravity = true;
|
||||
objectRigidbody.isKinematic = false;
|
||||
this.GetComponent<Collider>().enabled = true;
|
||||
objectRigidbody.AddForce(direcction * ThrowForce, ForceMode.Impulse);
|
||||
}
|
||||
|
||||
private void FixedUpdate(){
|
||||
|
||||
if (objectGrabPointTransform != null){
|
||||
|
||||
objectRigidbody.MovePosition(objectGrabPointTransform.position);
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetPosition()
|
||||
{
|
||||
transform.position = StartPosition;
|
||||
objectRigidbody.velocity = new Vector3(0, 0, 0);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue