33 lines
822 B
C#
33 lines
822 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class ForceZone : MonoBehaviour
|
|
{
|
|
public float force = 0;
|
|
public GameObject player;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
private void OnTriggerStay(Collider other)
|
|
{
|
|
Vector3 direction = other.transform.position - this.player.transform.position;
|
|
Debug.DrawRay(this.transform.position, direction);
|
|
|
|
Rigidbody otherRigidbody = other.transform.GetComponent<Rigidbody>();
|
|
if (otherRigidbody)
|
|
{
|
|
other.transform.GetComponent<Rigidbody>().AddForce(direction.normalized * this.force * Time.deltaTime, ForceMode.Impulse);
|
|
}
|
|
}
|
|
}
|