Exemplo n.º 1
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        Ziarenko z = collision.collider.GetComponent <Ziarenko>();

        if (z != null)
        {
            Destroy(z.gameObject);
        }
    }
Exemplo n.º 2
0
    // Returns true if there are any seeds.
    private bool Hunt()
    {
        float    odl       = float.PositiveInfinity;
        Ziarenko najblizej = null;

        if (Board.instance.seedsAll.Any())
        {
            // iterate root objects and do something
            for (int i = 0; i < Board.instance.seedsAll.Count; ++i)
            {
                Ziarenko z = Board.instance.seedsAll[i].GetComponent <Ziarenko>();;
                if (z != null)
                {
                    float o = (transform.position - Board.instance.seedsAll[i].transform.position).sqrMagnitude;
                    if (o < odl)
                    {
                        odl       = o;
                        najblizej = z;
                    }
                }
            }
            if (najblizej != null)
            {
                Vector2 diff  = najblizej.transform.position - transform.position;
                float   angle = Mathf.Atan2(diff.y, diff.x);
                angle = Mathf.Rad2Deg * angle;
                Quaternion targetRotation = Quaternion.Euler(0f, 0f, angle);

                transform.rotation = targetRotation;

                // zmieńmy jeszcze prędkość xd

                Rigidbody2D rb = GetComponent <Rigidbody2D>();
                rb.velocity        = targetRotation * (Vector3.right * walkSpeed);
                rb.angularVelocity = 0f;
                return(true);
            }
        }
        return(false);
    }