Exemple #1
0
    IEnumerator Idle()
    {
        var duration = Random.Range(0.5f, 0.7f);

        yield return(new WaitForSeconds(duration));

        var dir = HushPuppy.GenerateValidPosition(
            () => new Vector3(
                Random.Range(-distance, distance),
                Random.Range(-distance, distance)),
            (vec) => {
            var hit = Physics2D.BoxCast(
                this.transform.position,
                Vector2.one,
                0f,
                vec.normalized,
                vec.magnitude,
                1 << LayerMask.NameToLayer("Walls")
                    | (1 << LayerMask.NameToLayer("Stairs"))
                    | TilemapHelper.GetLayerMaskCreatureCollision(this.currFloorLevel)
                );
            var outOfBounds = !TilemapHelper.InsideSameRoom(
                this.transform.position,
                this.transform.position + vec,
                RoomManager.Get().dimensions
                );
            return(!hit && !outOfBounds);
        });

        this.target = this.transform.position + dir;
    }
    public static bool InPlayerRoom(GameObject obj)
    {
        var player = GameObject.FindGameObjectWithTag("Player");

        if (player == null)
        {
            return(false);
        }
        return(TilemapHelper.InsideSameRoom(
                   obj.transform.position,
                   player.transform.position,
                   RoomManager.Get().dimensions));
    }
    void Start()
    {
        foreach (var powder in GameObject.FindObjectsOfType <WhitePowder>())
        {
            if (TilemapHelper.InsideSameRoom(this.transform.position, powder.transform.position, RoomManager.Get().dimensions))
            {
                RegisterPowder(powder);
            }
        }

        if (spawnPoints.Count == 0)
        {
            Debug.LogError("This shouldn't be happening.");
            Debug.Break();
        }
    }