The implementation of Unity's build ladder algorithm. 1. The ladder shape can be set by creating the angle dynamically from the prefabricated object.1.1 mainly involves the transformation of mathematical knowledge points, angles and radians.
radians = angle multiplied by pi and divided by 180
Angle = radians divided by π and multiplied by 180.
1.2 Trigonometric Functions
Here only the tangent function tan is used, and the simple reasoning logic is as follows:
2.1 Below begins to look at the code PadelCreate.cs
1 usingUnityengine;2 usingSystem.Collections;3 4 5 Public classPadelcreate:monobehaviour6 {7 PublicGameobject Prb_padel;8 Public floatAngel = -;9 PrivateVector3 lastoneposition;Ten //Use this for initialization One voidStart () A { - Anyangelpadel (angel); - } the - /// <summary> - ///stair instances of any angle - /// </summary> + /// <param name= "Angel" ></param> - voidAnyangelpadel (floatAngel) + { A floatHudu = (Angel/ the) *Mathf.pi; at //up the stairs. - for(inti =0; I <7; i++) - { -Gameobject Tmppadel =(Gameobject) instantiate (Prb_padel); - floatyy = i *Mathf.tan (Hudu); -TmpPadel.transform.position =NewVector3 (-7+ I,-2+ yy,0); inLastoneposition =tmpPadel.transform.position; - } to //generate two horizontal directions + for(inti =0; I <2; i++) - { theGameobject Tmppadel =(Gameobject) instantiate (Prb_padel); *TmpPadel.transform.position =NewVector3 (lastoneposition.x+1, LASTONEPOSITION.Y,0); $Lastoneposition =tmpPadel.transform.position;Panax Notoginseng } - //Down Stairs the for(inti =0; I <7; i++) + { AGameobject Tmppadel =(Gameobject) instantiate (Prb_padel); the floatyy = i *Mathf.tan (Hudu); +TmpPadel.transform.position =NewVector3 (lastoneposition.x +i, Lastoneposition.y-yy,0); - //lastoneposition = tmpPadel.transform.position; $ } $ - } - the}
The structure of unity is as follows:
The preparation is complete, run it in unity!
The drawing is complete.
Unity Ladder Generation algorithm