Пример #1
0
 public static int[] Map(this int [] a, done fun)
 {
     //throw new NotImplementedException();
     for (int i = 0; i < a.Length; i++)
     {
         a[i] = fun(a[i]);
     }
     return(a);
 }
 // Use this for initialization
 void Start()
 {
     anim = GetComponent<Animator> ();
     rigid = GetComponent<Rigidbody> ();
     playerMode = done.Normal;
     //		radiusMagnet.SetActive (false);
     magnetMode = MGMode.Search;
 }
    // Update is called once per frame
    void Update()
    {
        currentBaseState = GetComponent<Animator> ().GetCurrentAnimatorStateInfo (0);
        if (playerMode == done.Normal)
        {
            playerMoving ();
            jumpPlayer (jumpPower);

        }

        else if (playerMode == done.Magnet)
        {
        //			if(!radiusMagnet.activeInHierarchy)
        //			{
        //				radiusMagnet.SetActive (true);
        //			}

            _GControl.MagnetPW -= 2 * Time.deltaTime;

            if(_GControl.MagnetPW <= 0)
            {
                playerMode = done.Normal;
        //				radiusMagnet.SetActive (false);
                _GControl.MagnetPW = GetComponent<PlayerAttribut>().MagnetPower;
            }
        }

        else if (playerMode == done.Events)
        {

        }

        else if (playerMode == done.Pause)
        {

        }

        if (Input.GetButton ("Magnet"))
        {
            if(playerMode != done.Magnet)
            {
                playerMode = done.Magnet;
                anim.SetFloat ("Supido", 0);
                rigid.velocity = new Vector3(0,0,0);
            }
        }
        else
        {
            playerMode = done.Normal;
        //			radiusMagnet.SetActive (false);
            _GControl.MagnetPW = GetComponent<PlayerAttribut>().MagnetPower;
        }
    }
    void OnTriggerStay(Collider col)
    {
        if (col.gameObject.tag == "Magnet")
        {
            if (playerMode == done.Magnet)
            {
                if(magnetMode == MGMode.Search)
                {
                    var wantedX = magnetObject.transform.position.x;
                    var wantedY = magnetObject.transform.position.y;
                    var currentX = col.transform.position.x;
                    var currentY = col.transform.position.y;
                    currentX = Mathf.Lerp (currentX,wantedX, 5 * Time.deltaTime);
                    currentY = Mathf.Lerp (currentY,wantedY, 5 * Time.deltaTime);

                    col.transform.position = new Vector3(currentX,currentY,
                                                         col.transform.position.z);

                    if(col.transform.position == magnetObject.transform.position)
                    {
                        magnetMode = MGMode.Pull;
                        objected = col.gameObject;
                    }
                }
                else if (magnetMode == MGMode.Pull)
                {
                    if(Input.GetButtonDown ("Cancel"))
                    {
                        testMagnet ();
                        magnetMode = MGMode.Search;
                        playerMode = done.Normal;
                    }
                }
            }
        }
    }