0
\$\begingroup\$

I disabled gamecontroller for 15.9 seconds and controller not awake again.It's for cutscene cam before the race start.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// Move and rotation camera controller
/// </summary>

public class CameraController :Singleton<CameraController>
{
    
    [SerializeField] List<CameraPreset> CamerasPreset = new List<CameraPreset>();   //Camera presets
    [SerializeField] CarController OverrideCar;
    private GameObject cam;
    int ActivePresetIndex = -1;
    public CameraPreset ActivePreset { get; private set; }

    CarController TargetCar { get { return OverrideCar?? GameController.PlayerCar; } }
    GameController GameController { get { return GameController.Instance; } }

    float SqrMinDistance;
    int CurrentFrame = 0;

    //The target point is calculated from velocity of car.
    Vector3 m_TargetPoint;
    Vector3 TargetPoint
    {
        get
        {
            if (CurrentFrame != Time.frameCount)
            {
                if (!OverrideCar && GameController == null || TargetCar == null)
                {
                    return transform.position;
                }
                m_TargetPoint = TargetCar.RB.velocity * ActivePreset.VelocityMultiplier;
                m_TargetPoint += TargetCar.transform.position;

                CurrentFrame = Time.frameCount;
            }
            return m_TargetPoint;
        }
    }

    protected override void AwakeSingleton ()
    {
        CamerasPreset.ForEach (c => c.CameraHolder.SetActive (false));

        ActivePresetIndex = GameOptions.ActiveCameraIndex;
        UpdateActiveCamera ();
    }

    private IEnumerator Start ()
    {
        cam = GameObject.FindGameObjectWithTag("cam");
        ActivePreset.EnableRotation = false;
        GameController.SetActive(false);
        yield return new WaitForSeconds (15.9f);
        GameController.SetActive(true);
        cam.SetActive(false);
        transform.position = TargetPoint;
        ActivePreset.CameraHolder.rotation = TargetCar.transform.rotation;
        ActivePreset.EnableRotation = true;
    
    } 
\$\endgroup\$
6
  • \$\begingroup\$ When you deactivate a GameObject, you also stop any coroutines running on it. Have you considered running the script that sleeps and wakes the game controller from somewhere else? \$\endgroup\$ Commented Dec 20, 2020 at 14:19
  • \$\begingroup\$ No have any coroutines in cameracontroller.Yes I considered some sleeps like countdowntimer from gamecontroller, but its not about of my cameracontroller issue.I edited code by the way. \$\endgroup\$ Commented Dec 20, 2020 at 15:10
  • \$\begingroup\$ It doesn't look like we have a Minimal Complete Verifiable Example we could use to replicate this problem in a new, empty project. Please edit your question to include all the code we'd need to reproduce the issue and test potential solutions to be sure they'd work. \$\endgroup\$ Commented Dec 20, 2020 at 15:15
  • \$\begingroup\$ I added gamecontroller code.Thank you btw. \$\endgroup\$ Commented Dec 20, 2020 at 15:23
  • 1
    \$\begingroup\$ This is not a Minimal Complete Verifiable Example. Firstly, the example needs to be Minimal - cut out any code that's not related to reproducing the problem. Next, the example needs to be Complete - we need to know how to set up scene objects with the scripts you've shared to mimic your setup. Right now we don't know whether these scripts are on the same object or different objects, or if one is a child of the other, etc. \$\endgroup\$ Commented Dec 20, 2020 at 15:26

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.