I have this white arms, which are scaling freely. At first all of them are at the center of the cube. When i tap, the first arm moves (scales) up, on second tap the second arm moves right, on the third tap the third arm moves down till the ground, creating an arc, and the cube moves by this trajectory. But I can’t get this to work - I don’t understand, how to stick each arms pivot to the ending of previous arm, which is moving.
Some additional pivots on the sprites would help me, as I can place them at the beginning and at the end of the arm, but I don’t know a way to implement this. Can anyone help me?
Ok, I’ve done it in a stupid way, but it actually works
public class Player : MonoBehaviour {
public int State = 0;
public GameObject arm1;
public GameObject arm2;
public GameObject arm3;
void Start () {
//Setting arms in default position and location
arm1.transform.localScale = new Vector3(1,0.2f);
arm2.transform.localScale = new Vector3(1,0.2f);
arm3.transform.localScale = new Vector3(1,0.2f);
arm1.transform.position = transform.position;
arm2.transform.position = transform.position;
arm3.transform.position = transform.position;
}
void Update () {
//sticking arms to the end of the previous arm
arm1.transform.position = transform.position;
arm2.transform.position = new Vector3 (arm1.transform.position.x, arm1.transform.position.y + arm1.transform.localScale.x, arm1.transform.position.z);
arm3.transform.position = new Vector3 (arm2.transform.position.x + arm2.transform.localScale.x, arm2.transform.position.y, arm2.transform.position.z);
if (Input.GetMouseButtonDown (0))
{
if (State < 3)
State++;
}
//on mouse click begin to transform arms
switch (State) {
case 1:
arm1.transform.localScale += new Vector3 (0.1f,0);
break;
case 2:
arm2.transform.localScale += new Vector3 (0.1f,0);
break;
case 3:
arm3.transform.localScale += new Vector3 (0.1f,0);
break;
}
