Пример #1
0
    private void DrawCarrot(Vector2Int chunkCoord, InfiniteChunks.Chunk chunk, GameObject asteroid, int asteroidSize)
    {
        GameObject carrot = carrotPool.GetFromPool(0);

        if (carrot == null)
        {
            return;
        }

        Vector2 dir = Random.insideUnitCircle.normalized * (asteroidSize + 1);

        carrot.transform.position = asteroid.transform.position + asteroid.transform.TransformDirection(dir);

        Vector3 targetRotateDir = asteroid.transform.position - carrot.transform.position;
        float   angle           = (Mathf.Atan2(targetRotateDir.y, targetRotateDir.x) * Mathf.Rad2Deg) - 90f;

        carrot.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);

        FixedJoint2D joint = carrot.GetComponent <FixedJoint2D>();

        joint.connectedBody = asteroid.GetComponent <Rigidbody2D>();

        Carrot script = carrot.GetComponent <Carrot>();

        script.SetPickupCallback(CarrotPickup, chunkCoord);
        carrot.SetActive(true);
        chunk.AddCarrot(carrot);
    }