Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class ScatterLive : MonoBehaviour
- {
- public string GroupName = "ScatterGrp";
- private GameObject ParentGroup;
- public GameObject ScatterObject;
- public float AttractionStrength = 1.0f;
- private List<GameObject> MoveList = new List<GameObject>();
- void Start()
- {
- ParentGroup = new GameObject(GroupName);
- foreach (Transform child in transform)
- {
- var NewScatterObj = (GameObject)Instantiate(ScatterObject, child.transform.position, child.transform.rotation, ParentGroup.transform);
- NewScatterObj.transform.localScale = child.transform.localScale;
- Debug.Log(NewScatterObj);
- MoveList.Add(NewScatterObj);
- }
- }
- void Update()
- {
- var i = 0;
- foreach (Transform child in transform)
- {
- Vector3 TargetObjPosition;
- TargetObjPosition = MoveList[i].transform.position;
- TargetObjPosition -= child.transform.position;
- MoveList[i].transform.position += (child.transform.position * AttractionStrength);
- i++;
- }
- }
- }
Add Comment
Please, Sign In to add comment