init
This commit is contained in:
commit
862afc9b7a
478 changed files with 197737 additions and 0 deletions
39
Assets/Scripts/GroundItem.cs
Normal file
39
Assets/Scripts/GroundItem.cs
Normal file
|
@ -0,0 +1,39 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class GroundItem : MonoBehaviour
|
||||
{
|
||||
public float Radius;
|
||||
public GameObject selfPrefab;
|
||||
GameObject target;
|
||||
void Start()
|
||||
{
|
||||
target = findPlayer();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
Vector3 Dist = target.transform.position - gameObject.transform.position;
|
||||
if ((Dist).magnitude <= Radius) {
|
||||
Rigidbody2D rb = gameObject.GetComponent<Rigidbody2D>();
|
||||
rb.AddForce(Dist.normalized * rb.mass * Mathf.Sqrt(Dist.magnitude) * 3);
|
||||
if ((Dist).magnitude <= 1) {
|
||||
Inventory.addItem(selfPrefab);
|
||||
Object.Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GameObject findPlayer() {
|
||||
GameObject returnObj = null;
|
||||
foreach(GameObject go in Object.FindObjectsOfType<GameObject>()) {
|
||||
if (go.name.Equals("Player")) {
|
||||
returnObj = go;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return returnObj;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue