init
This commit is contained in:
commit
341a877b4a
2338 changed files with 1346408 additions and 0 deletions
32
Assets/Scripts/WeightedLocation.cs
Normal file
32
Assets/Scripts/WeightedLocation.cs
Normal file
|
@ -0,0 +1,32 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class WeightedLocation : MonoBehaviour
|
||||
{
|
||||
[System.Serializable]
|
||||
public struct WeightedTarget
|
||||
{
|
||||
public Transform t;
|
||||
public float weight;
|
||||
}
|
||||
|
||||
|
||||
public List<WeightedTarget> targets;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
transform.position = Vector3.zero;
|
||||
Vector3 pos = Vector3.zero;
|
||||
Vector3 pivot = targets[0].t.position;
|
||||
|
||||
float factor = 0;
|
||||
foreach(WeightedTarget t in targets)
|
||||
{
|
||||
pos += t.t.position * t.weight;;
|
||||
factor += t.weight;
|
||||
}
|
||||
pos /= (factor);
|
||||
transform.position = pos;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue