コード例 #1
0
ファイル: SharkControl.cs プロジェクト: kenhoff/LD29
    void doIdleThings()
    {
        SharkTimeOnCurrentDirection += Time.deltaTime;

        if (SharkTimeOnCurrentDirection > SharkIdleSwitchTime)
        {
            if (Random.value >= 0.5)
            {
                currentFacingDirection = SharkFacingDirection.Right;
            }
            else
            {
                currentFacingDirection = SharkFacingDirection.Left;
            }
            SharkTimeOnCurrentDirection = 0.0f;
        }

        switch (currentFacingDirection)
        {
        case SharkFacingDirection.Left:
            currentTarget = transform.position + new Vector3(-1, 0, 0);
            break;

        case SharkFacingDirection.Right:
            currentTarget = transform.position + new Vector3(1, 0, 0);
            break;
        }

        rigidbody2D.AddForce(transform.up * SharkIdleForce * Time.deltaTime);

        if (transform.position.x > SharkDistanceLimit)
        {
            currentFacingDirection = SharkFacingDirection.Left;
        }
        if (transform.position.x < -SharkDistanceLimit)
        {
            currentFacingDirection = SharkFacingDirection.Right;
        }

        adjustHeading(currentTarget);

        // adjust heading towards target
    }
コード例 #2
0
ファイル: SharkControl.cs プロジェクト: kenhoff/LD29
 void OnCollisionEnter2D(Collision2D collision)
 {
     if (currentState == AIState.Idle)
     {
         if (currentFacingDirection == SharkFacingDirection.Right)
         {
             currentFacingDirection = SharkFacingDirection.Left;
         }
         else
         {
             currentFacingDirection = SharkFacingDirection.Right;
         }
     }
     if (currentState == AIState.Attack)
     {
         if (collision.gameObject.tag == "Player")
         {
             Debug.Log("attacking player");
             collision.gameObject.GetComponent <PlayerControl>().Damage(Time.deltaTime * SharkAttackDamage);
         }
     }
 }
コード例 #3
0
ファイル: SharkControl.cs プロジェクト: kenhoff/LD29
    void doIdleThings()
    {
        SharkTimeOnCurrentDirection += Time.deltaTime;

        if (SharkTimeOnCurrentDirection > SharkIdleSwitchTime) {
            if (Random.value >= 0.5) {
                currentFacingDirection = SharkFacingDirection.Right;
            }
            else {
                currentFacingDirection = SharkFacingDirection.Left;
            }
            SharkTimeOnCurrentDirection = 0.0f;
        }

        switch (currentFacingDirection) {
            case SharkFacingDirection.Left:
                currentTarget = transform.position + new Vector3(-1, 0, 0);
                break;
            case SharkFacingDirection.Right:
                currentTarget = transform.position + new Vector3(1, 0, 0);
                break;

        }

        rigidbody2D.AddForce(transform.up * SharkIdleForce * Time.deltaTime);

        if (transform.position.x > SharkDistanceLimit) {
            currentFacingDirection = SharkFacingDirection.Left;
        }
        if (transform.position.x < -SharkDistanceLimit) {

            currentFacingDirection = SharkFacingDirection.Right;
        }

        adjustHeading(currentTarget);

        // adjust heading towards target
    }
コード例 #4
0
ファイル: SharkControl.cs プロジェクト: kenhoff/LD29
 void OnCollisionEnter2D(Collision2D collision)
 {
     if (currentState == AIState.Idle) {
         if (currentFacingDirection == SharkFacingDirection.Right) {
             currentFacingDirection = SharkFacingDirection.Left;
         }
         else {
             currentFacingDirection = SharkFacingDirection.Right;
         }
     }
     if (currentState == AIState.Attack) {
         if (collision.gameObject.tag == "Player") {
             Debug.Log("attacking player");
             collision.gameObject.GetComponent<PlayerControl>().Damage(Time.deltaTime * SharkAttackDamage);
         }
     }
 }