コード例 #1
0
    private void DoAction()
    {
        Vector3 charPos = transform.position;

        charPos.z -= 0.2f;

        leftArm.GetComponent <Rigidbody>().AddForce(new Vector3(0.0f, 0.0f, armForce));
        rightArm.GetComponent <Rigidbody>().AddForce(new Vector3(0.0f, 0.0f, armForce));

        AI_Ctrl ai_script      = parentPrefab.GetComponent <AI_Ctrl>();
        float   parentDistance = 10.0f;

        if (ai_script != null)
        {
            parentDistance = ai_script.kidParentDistance;
        }
        if (parentDistance >= 2f)
        {
            Collider[] hitColliders = Physics.OverlapSphere(actionSphere.transform.position, actionSphere.GetComponent <SphereCollider>().radius);
            for (int i = 0; i < hitColliders.Length; i++)
            {
                IInteractable obj = hitColliders[i].GetComponent <IInteractable>();
                if (obj != null)
                {
                    obj.OnAction();
                }
            }
        }
        else
        {
            //Debug.Log("Parent is too close");
        }
    }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        if (replaying)
        {
            if (history.Count > 0)
            {
                this.transform.position = history[0].position;
                this.transform.rotation = history[0].rotation;
                if (history[0].action)
                {
                    DoAction();
                }
                if (history[0].playSound && !playingScoldSound)
                {
                    SoundManager.instance.RandomizeSfx(actionSound1, actionSound2);
                }

                history.RemoveAt(0);
            }
        }
        else
        {
            // Keep kid always vertical
            Transform kidTransform   = GetComponent <Transform>();
            Vector3   kidEulerAngles = transform.eulerAngles;
            kidTransform.rotation = Quaternion.Euler(0.0f, kidEulerAngles.y, 0.0f);

            // Go Left
            if (Input.GetButton("Button1"))
            {
                transform.RotateAround(leftLeg.position, new Vector3(0.0f, 1.0f, 0.0f), -rotationSpeed * Time.deltaTime);
            }

            else if (Input.GetButton("Button2"))
            {
                transform.RotateAround(rightLeg.position, new Vector3(0.0f, 1.0f, 0.0f), rotationSpeed * Time.deltaTime);
            }

            Rigidbody rb = GetComponent <Rigidbody>();
            if (Input.GetButtonUp("Button1") || Input.GetButtonUp("Button2"))
            {
                rb.freezeRotation = true;
                if (!playingScoldSound)
                {
                    SoundManager.instance.RandomizeSfx(actionSound1, actionSound2);
                }
            }
            else
            {
                rb.freezeRotation = false;
            }

            if (Input.GetButtonDown("Button3"))
            {
                DoAction();
            }

            if (recording)
            {
                history.Add(new SimpleTransform
                {
                    position  = transform.position,
                    rotation  = transform.rotation,
                    action    = Input.GetButtonDown("Button3"),
                    playSound = Input.GetButtonUp("Button1") || Input.GetButtonUp("Button2")
                }
                            );
            }

            AI_Ctrl ai_script      = parentPrefab.GetComponent <AI_Ctrl>();
            float   parentDistance = 10.0f;
            if (ai_script != null)
            {
                parentDistance = ai_script.kidParentDistance;
            }
            //Debug.Log(parentDistance.ToString() + "  " + playingScoldSound.ToString());
            if (parentDistance < 2f && !playingScoldSound)
            {
                if (ai_script.DebugAIState == AI_Ctrl.AIStates.blocking)
                {
                    SoundManager.instance.PlaySingle(scoldSound2);
                }
                else
                {
                    SoundManager.instance.PlaySingle(scoldSound1);
                }
                playingScoldSound = true;
                //Debug.Log("Playing");
            }
            else if (parentDistance > 2.2f)
            {
                playingScoldSound = false;
                //Debug.Log("Too Far");
            }
        }
    }
コード例 #3
0
ファイル: SceneMgr.cs プロジェクト: antoinetd/gamejam-cml
    private void Update()
    {
        currentTimer -= Time.deltaTime;
        if (doSwitch && currentTimer < 0f && !credit)
        {
            credit = true;
            SceneManager.LoadScene("CreditsScreen");
        }
        if ((Input.GetButtonDown("ChangeToParent") || currentTimer < 0f) && doSwitch == false)
        {
            KidControls kidControls = (KidControls)FindObjectOfType(typeof(KidControls));
            // If we are already in parent mode do nothing
            if (kidControls.recording == false && kidControls.replaying == true)
            {
                return;
            }

            history_backup = new List <KidControls.SimpleTransform>();
            foreach (KidControls.SimpleTransform item in kidControls.history)
            {
                history_backup.Add(item);
            }
            Scene scene = SceneManager.GetActiveScene();
            SceneManager.LoadScene(scene.name);

            doSwitch     = true;
            currentTimer = 120f;
        }

        if (doSwitch)
        {
            frameCounter++;
        }

        if (frameCounter == 10)
        {
            currentTimer = 120f;
            KidControls kidControls = (KidControls)FindObjectOfType(typeof(KidControls));

            KidControls          kidControlsNewScene = (KidControls)FindObjectOfType(typeof(KidControls));
            ParentManualControls parentControls      = (ParentManualControls)FindObjectOfType(typeof(ParentManualControls));
            AI_Ctrl ai_ctrl = (AI_Ctrl)FindObjectOfType(typeof(AI_Ctrl));

            if (kidControlsNewScene != null)
            {
                kidControls.history           = history_backup;
                kidControlsNewScene.recording = false;
                kidControlsNewScene.replaying = true;
            }
            if (parentControls != null)
            {
                parentControls.activateManualControls = true;
                var navMesh = parentControls.gameObject.GetComponent <NavMeshAgent>();
                if (navMesh != null)
                {
                    navMesh.enabled = false;
                }
            }
            if (ai_ctrl != null)
            {
                ai_ctrl.enableParent = false;
                var bc = ai_ctrl.GetComponent <BoxCollider>();
                if (bc != null)
                {
                    bc.enabled = true;
                }
                var cc = ai_ctrl.GetComponent <CapsuleCollider>();
                if (cc != null)
                {
                    cc.enabled = true;
                }
            }
            GameManager_Scoring.GetInstance().isAdult = true;
        }
    }