forked from renaissanceCoder/Simple-Scripting-Series
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MatthiasWindZone.cs
34 lines (29 loc) · 981 Bytes
/
MatthiasWindZone.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MatthiasWindZone : MonoBehaviour {
List<Rigidbody> RigidbodiesInWindZoneList = new List<Rigidbody>();
public Vector3 windDirection = Vector3.right;
public float windStrength = 5;
private void OnTriggerEnter(Collider col)
{
Rigidbody objectRigid = col.gameObject.GetComponent<Rigidbody>();
if(objectRigid != null)
RigidbodiesInWindZoneList.Add(objectRigid);
}
private void OnTriggerExit(Collider col)
{
Rigidbody objectRigid = col.gameObject.GetComponent<Rigidbody>();
if (objectRigid != null)
RigidbodiesInWindZoneList.Remove(objectRigid);
}
private void FixedUpdate()
{
if(RigidbodiesInWindZoneList.Count > 0) {
foreach (Rigidbody rigid in RigidbodiesInWindZoneList)
{
rigid.AddForce(windDirection * windStrength);
}
}
}
}