Пример #1
0
    private void CreateBreakableWall(LevelCell cell, LevelCell otherCell, LevelDirection direction, Canvas twoDMap)
    {
        LevelBreakableWall wall = Instantiate(breakableWallPrefab) as LevelBreakableWall;

        wall.material = breakableMats[cell.room.matIndex];
        wall.Initialize(cell, otherCell, direction);
        breakableWalls.Add(wall);
        LevelBreakableWall otherWall = Instantiate(breakableWallPrefab) as LevelBreakableWall;

        otherWall.material = breakableMats[otherCell.room.matIndex];
        otherWall.Initialize(otherCell, cell, direction.GetOpposite());
        breakableWalls.Add(otherWall);
        CreateTwoDWall(cell, twoDMap, direction);
    }
Пример #2
0
    private IEnumerator SwingAnimation()
    {
        hit = false;
        float      rotation        = 0.0f;
        Vector3    defaultPosition = gameObject.transform.GetChild(1).localPosition;
        Quaternion defaultRotation = gameObject.transform.GetChild(1).localRotation;

        while (rotation < 75.0f)
        {
            gameObject.transform.GetChild(1).localRotation = defaultRotation;
            gameObject.transform.GetChild(1).localPosition = defaultPosition;
            Vector3 pivot = gameObject.transform.GetChild(1).position + new Vector3(0.0f, -.25f, 0.0f);
            Vector3 axis  = gameObject.transform.GetChild(1).forward;
            rotation += 400.0f * Time.deltaTime;
            gameObject.transform.GetChild(1).RotateAround(pivot, axis, rotation);
            gameObject.transform.GetChild(1).RotateAround(pivot, gameObject.transform.GetChild(1).right, -(rotation * .2f));
            yield return(new WaitForSeconds(0.0f));
        }
        RaycastHit[] hitInfos = Physics.RaycastAll(gameObject.transform.position, gameObject.transform.forward, 0.5f);
        if (hitInfos.Length > 0)
        {
            foreach (RaycastHit info in hitInfos)
            {
                if (!hit)
                {
                    GameObject collided = info.collider.gameObject;
                    if (collided.tag == "Unit")
                    {
                        Unit unitHit = collided.transform.parent.gameObject.GetComponent <Unit>();
                        if (unitHit.team.Equals(team.enemyTeam))
                        {
                            hit             = true;
                            unitHit.health -= 1;
                        }
                    }
                    else if (collided.tag == "Breakable")
                    {
                        hit = true;
                        LevelBreakableWall wall = collided.transform.parent.gameObject.GetComponent <LevelBreakableWall>();
                        wall.health -= 1;
                    }
                }
            }
        }
        else
        {
            hit = false;
        }
        while (rotation > 0.0f)
        {
            gameObject.transform.GetChild(1).localRotation = defaultRotation;
            gameObject.transform.GetChild(1).localPosition = defaultPosition;
            Vector3 pivot = gameObject.transform.GetChild(1).position + new Vector3(0.0f, -.25f, 0.0f);
            Vector3 axis  = gameObject.transform.GetChild(1).forward;
            rotation -= 400.0f * Time.deltaTime;
            gameObject.transform.GetChild(1).RotateAround(pivot, axis, rotation);
            gameObject.transform.GetChild(1).RotateAround(pivot, gameObject.transform.GetChild(1).right, -(rotation * .2f));
            yield return(new WaitForSeconds(0.0f));
        }
        gameObject.transform.GetChild(1).localRotation = defaultRotation;
        gameObject.transform.GetChild(1).localPosition = defaultPosition;
        swinging = false;
    }