Exemplo n.º 1
0
 void SetClosetStatus(bool playerHidden)
 {
     if (playerHidden)
     {
         if (SneakerPlayer.mySecretPlace != null)
         {
             return;
         }
         hidden = playerHidden;
         closetSpriteAnimation.SetAnimation("busy");
         SneakerPlayer.mySecretPlace          = gameObject;
         GlobalHandler.Instance.player.status = SneakerPlayer.PlayerStatus.hidden;
     }
     else
     {
         if (SneakerPlayer.mySecretPlace != gameObject)
         {
             return;
         }
         hidden = playerHidden;
         closetSpriteAnimation.SetAnimation("idle");
         SneakerPlayer.mySecretPlace          = null;
         GlobalHandler.Instance.player.status = SneakerPlayer.PlayerStatus.playing;
     }
 }
Exemplo n.º 2
0
 public void Respawn()
 {
     //gameObject.SetActiveRecursively(false);
     transform.position = spawnPoint;
     //gameObject.SetActiveRecursively(true);
     status        = PlayerStatus.playing;
     searchedDesk  = false;
     mySecretPlace = null;
     spriteAnimation.SetAnimation("idle");
 }
Exemplo n.º 3
0
 void PlayerOutside(bool force)
 {
     if (SneakerPlayer.mySecretPlace == gameObject || force)
     {
         ActiveState.SetActive(GlobalHandler.Instance.upArrow, false);
         // Reset copier display
         copierSpriteAnimation.SetAnimation("idle");
         hidden = false;
         SneakerPlayer.mySecretPlace = null;
     }
 }
Exemplo n.º 4
0
 void SetCarStatus()
 {
     if (opened)
     {
         carSpriteAnimation.SetAnimation("opened");
         GlobalHandler.Instance.fxSource.PlayOneShot(openDoorAudioClip);
     }
     else
     {
         carSpriteAnimation.SetAnimation("closed");
         GlobalHandler.Instance.fxSource.PlayOneShot(openDoorAudioClip);
     }
 }
    void SetDoorStatus(bool newStatus)
    {
        if (newStatus == opened)
        {
            return;
        }

        opened = newStatus;
        if (opened)
        {
            doorSprite.SetAnimation("opened");
            doorCollider.enabled = false;
        }
        else
        {
            doorSprite.SetAnimation("closed");
            doorCollider.enabled = true;
        }
    }
Exemplo n.º 6
0
    // Update is called once per frame
    void Update()
    {
        if (status == GuardStatus.alert && GlobalHandler.Instance.player.status != SneakerPlayer.PlayerStatus.busted)
        {
            visionMeshRenderer.material.SetColor("_EmisColor", normalVision);
            status = GuardStatus.idle;
        }
        if (status == GuardStatus.idle && Time.time > nextMove)
        {
            status = GuardStatus.moving;
            // Set sprite animation
            spriteAnimation.SetAnimation("walk");
        }
        if (status == GuardStatus.moving)
        {
            if (!orientationChanged)
            {
                direction = (patrol[currentWaypoint].calculatedPosition - transform.position).normalized;
                Vector3 scale = sprite.transform.localScale;
                scale.x = Mathf.Abs(scale.x) * direction.x;
                sprite.transform.localScale = scale;
                orientationChanged          = true;
            }
            // Draw line between here and destination
            Debug.DrawLine(transform.position, patrol[currentWaypoint].calculatedPosition, Color.red);
            transform.Translate(direction * patrol[currentWaypoint].speedToReach * Time.deltaTime);

            //Debug.Log ("Approaching next wp : " + (patrol[currentWaypoint].position-transform.position).sqrMagnitude);
            if ((direction.x < 0 && patrol[currentWaypoint].calculatedPosition.x > transform.position.x) || (direction.x > 0 && patrol[currentWaypoint].calculatedPosition.x < transform.position.x))
            {
                // Pause when arrived
                nextMove = Time.time + patrol[currentWaypoint].pauseWhenArrived;
                status   = GuardStatus.idle;
                // Set sprite (not animated)
                spriteAnimation.SetAnimation("idle");
                // Set next waypoint
                currentWaypoint++;
                if (currentWaypoint >= patrol.Length)
                {
                    currentWaypoint = 0;
                }
                orientationChanged = false;
                //Debug.Log ("Setting next waypoint<" + currentWaypoint + "> : " + patrol[currentWaypoint].position + " direction " + direction);
            }
        }
        // Vision : raycast up/down
        //Vector3 visionDirection = Vector3.right * direction.x * defaultVisionLength / (root.transform.localScale.x*Camera.main.orthographicSize);
        Vector3 visionDirection = Vector3.right * direction.x * defaultVisionLength;
        Ray     visionRay       = new Ray(transform.position + Vector3.Scale(new Vector3(direction.x, 1, 1), visionOffset), visionDirection);

        Debug.DrawRay(visionRay.origin, visionRay.direction * defaultVisionLength, Color.cyan, 2f);
        //Debug.DrawLine(transform.position + coneDeVision.vertices[0], transform.position + coneDeVision.vertices[1], Color.yellow);
        //Debug.DrawLine(transform.position + coneDeVision.vertices[0], transform.position + coneDeVision.vertices[2], Color.yellow);
        //Debug.DrawLine(transform.position + Vector3.Scale(coneDeVision.vertices[0], root.transform.localScale), transform.position + Vector3.Scale(coneDeVision.vertices[1], root.transform.localScale), Color.yellow);
        //Debug.DrawLine(transform.position + Vector3.Scale(coneDeVision.vertices[0], root.transform.localScale), transform.position + Vector3.Scale(coneDeVision.vertices[2], root.transform.localScale), Color.yellow);

        hitInfoList = Physics.RaycastAll(visionRay);
        bool     hit      = false;
        float    distance = defaultVisionLength + 1;
        Collider nearestUsefulCollider = null;

        if (hitInfoList.Length > 0)
        {
            for (int i = 0; i < hitInfoList.Length; i++)
            {
                RaycastHit hitInfo = hitInfoList[i];
                // Do not take into account triggers
                if (hitInfo.collider.isTrigger)
                {
                    continue;
                }
                // Do not take into account guards
                if (hitInfo.collider.GetComponent <Guard>() != null)
                {
                    continue;
                }

                // Is hit distance closer than previous one and in range ?
                if (hitInfo.distance < distance && hitInfo.distance <= defaultVisionLength)
                {
                    nearestUsefulCollider = hitInfo.collider;
                    distance = hitInfo.distance;
                    hit      = true;
                }
            }
        }
        // If we hit something, check the nearest collider
        if (hit)
        {
            // Check if player is hidden or.. busted !
            if (nearestUsefulCollider.CompareTag("Player"))
            {
                if (GlobalHandler.Instance.player.status == SneakerPlayer.PlayerStatus.hidden)
                {
                    hit = false;
                }
                else if (GlobalHandler.Instance.player.status != SneakerPlayer.PlayerStatus.busted)
                {
                    // Say to the player he's busted !
                    GlobalHandler.Instance.player.status = SneakerPlayer.PlayerStatus.busted;
                    SneakerPlayer.mySecretPlace          = null;
                    status = GuardStatus.alert;
                    visionMeshRenderer.material.SetColor("_EmisColor", alertVision);
                    // Guard stops
                    spriteAnimation.SetAnimation("idle");
                }
            }
        }
        if (!hit)
        {
            visionLength = defaultVisionLength;
            visionHeight = defaultVisionHeight;
        }
        else
        {
            visionLength = distance;
            visionHeight = defaultVisionHeight * visionLength / defaultVisionLength;
        }
    }