1. Prepare the object we want to clone: gold coins
public gameobject coin;
2. Calculate the function of the parabola and figure out the location of the clone according to the function:
<summary>// Cloning of parabolic gold coins////</summary>// <param name= "pos" > Clone the location of the first gold coin </ Param> //<param name= "num" > Clone gold Number </param> //<param name= "spacing" > distance between 22 coins </ param> void Loadcoinmethod (Vector3 pos,int num,float spacing) { Vector2 inityz = new Vector2 (pos.z, POS.Y)///record parabolic first gold position float Sysmmetryaxis = inityz.x + (num/2 + (num% 2 = = 0)? 0.5f:1) * spacing;//calculates parabola symmetry
float hight = inityz.y + Mathf.pow ((pos.z + Spacing-sysmmetryaxis), 2)/num;//parabolic 0 parameters for (int i = 0; i < nu M i++) { pos.z + = spacing; Pos.y = Hight-mathf.pow ((Pos.z-sysmmetryaxis), 2)/num; Gameobject Tempcoin = (gameobject) instantiate (coin,pos,quaternion.identity); } }
3. View (num = 15,spacing = 1.2f):
Unity cloning parabolic gold coin method