예제 #1
0
    IEnumerator Repair()
    {
        slider.gameObject.SetActive(true);
        float startTime = Time.time + repairTime;

        repairing = true;
        while (repairing)
        {
            if (slider != null)
            {
                slider.value = (startTime - Time.time) / repairTime;
            }

            if (startTime < Time.time)
            {
                repairTarget.Disable();
                damageamount--;
                repairing    = false;
                interracting = false;
                firstPersonController.enabled = true;
                state = Interraction.Moving;
                slider.gameObject.SetActive(false);
                SetLightColor("Light1", new Color(0, 1, 0));
                SetLightColor("Light2", new Color(0, 1, 0));
            }
            yield return(null);
        }
    }
예제 #2
0
 void RemoveFocus()
 {
     if (focus != null)
     {
         focus.PlusFocus();
         focus = null;
     }
 }
예제 #3
0
 void SetFocus(Interraction newFocus)
 {
     if (focus != null && focus != newFocus)
     {
         focus.PlusFocus();
     }
     focus = newFocus;
     newFocus.Focus(this);
 }
예제 #4
0
    void Update()
    {
        //Level-UP
        if (Experience >= ExperienceMax)
        {
            Level         += 1;
            Experience    -= ExperienceMax;
            ExperienceMax *= 1.5f;
            UpdateStatus(Level);
            GameObject LVLUP = Instantiate(Animlvlup, transform.position, Quaternion.identity.normalized);
            Destroy(LVLUP, 5);
        }

        if (isGrounded())
        {
            moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
            moveDirection = transform.TransformDirection(moveDirection);

            if (Input.GetKey(KeyCode.LeftShift))
            {
                moveDirection *= runspeed;
                IsRunning      = true;
                IsWalking      = false;
            }
            else
            {
                moveDirection *= speed;
                IsRunning      = false;
                IsWalking      = true;
            }


            if (Input.GetKey(KeyCode.Space))
            {
                moveDirection.y = jumpSpeed;
            }

            if (moveDirection.x == 0 || moveDirection.z == 0)
            {
                IsWalking = false;
            }
        }
        moveDirection.y -= gravity * Time.deltaTime;
        anim.SetBool("IsRunning", IsRunning);
        anim.SetBool("IsWalking", IsWalking);
        cc.Move(moveDirection * Time.deltaTime);

        if (Input.GetKeyDown(KeyCode.Mouse0) && !isAttacking)
        {
            Attack();
        }
        else
        {
            currentCooldown -= Time.deltaTime;

            if (currentCooldown <= 0)
            {
                currentCooldown = attackCooldown;
                isAttacking     = false;
            }
        }
        if (Input.GetKeyDown(inputInterract))
        {
            Targets = FindObjectsOfType <Interraction>();
            foreach (var Target in Targets)
            {
                if (Vector3.Distance(Target.transform.position, transform.position) <= interractRange)
                {
                    Interraction interraction = Target.GetComponent <Interraction>();
                    if (interraction) //On vérifie qu'on a une interraction
                    {
                        Debug.Log("On tient un truc là !");
                        SetFocus(interraction);
                        interraction.Interract(this);
                        return;
                    }
                    else
                    {
                        Debug.Log("Trop loin");
                    }
                }
            }
        }

        //Lacher le focus
        if (Input.GetKeyDown(KeyCode.F4))
        {
            RemoveFocus();
        }
    }
예제 #5
0
    void Update()
    {
        switch (state)
        {
        case Interraction.Moving:
            break;

        case Interraction.Driving:
            Drive();
            break;

        case Interraction.Fixing:
            if (repairing == false)
            {
                StartCoroutine(Repair());
            }
            return;

            break;

        case Interraction.Depth:
            Depth();
            break;
        }

        string[]   list = { "Steering", "Acceleration", "Damage", "DepthMeter", "DivingAngle" };
        RaycastHit hit2;
        var        layerMask2 = 1 << 8;

        if (Physics.Raycast(firstPersonController.m_Camera.transform.position, firstPersonController.m_Camera.transform.forward, out hit2, 5, layerMask2))
        {
            for (int i = 0; i < list.Length; i++)
            {
                if (hit2.transform.parent.name.Contains(list[i]))
                {
                    objectName.text = list[i];
                    break;
                }
            }
        }
        else
        {
            objectName.text = "";
        }


        if (Input.GetKeyDown(KeyCode.E))
        {
            if (interracting == true)
            {
                interracting = false;
                firstPersonController.enabled = true;
                state = Interraction.Moving;
                return;
            }
            Debug.DrawRay(firstPersonController.m_Camera.transform.position, firstPersonController.m_Camera.transform.forward, Color.cyan, 25);
            RaycastHit hit;
            var        layerMask = 1 << 8;
            if (Physics.Raycast(firstPersonController.m_Camera.transform.position, firstPersonController.m_Camera.transform.forward, out hit, 5, layerMask))
            {
                switch (hit.transform.tag)
                {
                case "DrivingWheel":
                    state = Interraction.Driving;
                    break;

                case "DepthPanel":
                    state = Interraction.Depth;
                    break;

                case "Damage":
                    state        = Interraction.Fixing;
                    repairTarget = hit.transform.GetComponent <Damage>();
                    break;
                }
                firstPersonController.enabled = !firstPersonController.enabled;
                interracting = true;
            }
        }
    }