cwisbg

ScatterLive

Nov 12th, 2018
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class ScatterLive : MonoBehaviour
  6. {
  7.     public string GroupName = "ScatterGrp";
  8.     private GameObject ParentGroup;
  9.     public GameObject ScatterObject;
  10.     public float AttractionStrength = 1.0f;
  11.     private List<GameObject> MoveList = new List<GameObject>();
  12.     void Start()
  13.     {
  14.         ParentGroup = new GameObject(GroupName);
  15.         foreach (Transform child in transform)
  16.         {
  17.             var NewScatterObj = (GameObject)Instantiate(ScatterObject, child.transform.position, child.transform.rotation, ParentGroup.transform);
  18.             NewScatterObj.transform.localScale = child.transform.localScale;
  19.             Debug.Log(NewScatterObj);
  20.             MoveList.Add(NewScatterObj);
  21.         }
  22.     }
  23.  
  24.     void Update()
  25.     {
  26.         var i = 0;
  27.         foreach (Transform child in transform)
  28.         {
  29.             Vector3 TargetObjPosition;
  30.             TargetObjPosition = MoveList[i].transform.position;
  31.             TargetObjPosition -= child.transform.position;
  32.             MoveList[i].transform.position += (child.transform.position * AttractionStrength);
  33.             i++;
  34.         }
  35.     }
  36.  
  37. }
Add Comment
Please, Sign In to add comment