The problem with code GameSession dose not contain a definition for "Lenght"

I still having an issue with < .length >

using System;

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.SceneManagement;

public class GameSesion : MonoBehaviour

{

[SerializeField] int playerLives = 3 ;



void Awake()

{

    int numGameSessions = FindObjectOfType<GameSesion>().Length;

    if (numGameSessions > 1)

    {

        Destroy(gameObject);

    }

    else

    {

        DontDestroyOnLoad(gameObject);

    }

}

public void ProcessPlayerDeath()

{

    if(playerLives > 1)

    {

        TakeLife();

    }

    else

    {

        ResetGameSesion();

    }

}

void TakeLife()

{

    playerLives = playerLives -1 ;

    int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;

    SceneManager.LoadScene(currentSceneIndex);

}

void ResetGameSesion()

{

    SceneManager.LoadScene(0);

    Destroy(gameObject);

}

}

it should be FindObjectsofType, not findOBJECToftype.

Also, have you misspelled in the Editor as well? cos that could maybe do it.

1 Like

yea allways is my bad english :smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms