1

Quem puder me ajudar, estou precisando muito. É um projeto para um jogo no Unity 2d:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//using player ;
//using Monobehaviour;
namespace player
{
}
namespace teste {


abstract class pl2  {
}   

}


 //namespace Monobehaviour{
namespace Player {


//public class Player : Monobehaviour{


public class player2 {

    //pl1  player = new Player ();


    player2 pl = new pl2 () ;


    void OnTriggerEnter2D(Collider2D other){

        if(other.gameObject.tag == "Player"){
            other.gameObject.GetComponent<Player>().alive = false;
            Time.timeScale = 0; 
        }
    }


    void Start () {
        Time.timeScale = 1;

        pauseObjects = GameObject.FindGameObjectsWithTag("ShowOnPause");            //gets all objects with tag ShowOnPause
        finishObjects = GameObject.FindGameObjectsWithTag("ShowOnFinish");          //gets all objects with tag ShowOnFinish

        hidePaused();
        hideFinished();

        if(Application.loadedLevelName == "MainLevel")
            playerController = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>();
    }


    void Update () {

        if(Input.GetKeyDown(KeyCode.P)){
            if(Time.timeScale == 1 && player.alive == true){
                Time.timeScale = 0;
                showPaused();
            } else if (Time.timeScale == 0 && player.alive == true){
                Time.timeScale = 1;
                hidePaused();
            }
        }
    }

    public void Reload(){
        Application.LoadLevel(Application.loadedLevel);
    }


    public void pauseControl(){
        if(Time.timeScale == 1){
            Time.timeScale = 0;
            showPaused();
        } else if (Time.timeScale == 0){
            Time.timeScale = 1;
            hidePaused();
        }
    }

    public void showPaused(){
        foreach(GameObject g in pauseObjects){
            g.SetActive(true);
        }
    }

    //hides objects with ShowOnPause tag
    public void hidePaused(){
        foreach(GameObject g in pauseObjects){
            g.SetActive(false);
        }
    }

    //shows objects with ShowOnFinish tag
    public void showFinished(){
        foreach(GameObject g in finishObjects){
            g.SetActive(true);
        }
    }

    //hides objects with ShowOnFinish tag
    public void hideFinished(){
        foreach(GameObject g in finishObjects){
            g.SetActive(false);
        }
    }

    //loads inputted level
    public void LoadLevel(string level){
        Application.LoadLevel(level);
    }       



    GameObject [] pauseObjects;
    GameObject [] finishObjects;
    player Player;

    }


    }
1
  • não era pra ser player2 invés de player?
    – isaque
    Commented 14/09/2017 às 21:59

1 Resposta 1

1

Você criou um namespace player e não botou nem uma classe dentro, você nunca vai conseguir criar uma variável de um namespace. Não era para ser player2 no lugar de player? Pois você deve ter escrito errado. e você nunca vai conseguir botar esse script em um gameobject, porque ele não herda do MonoBehaviour. Você modificar de public class player2 para public class player2 : MonoBehaviour. Tá aí o código pronto:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace teste {

namespace Player {

public class player2 : MonoBehaviour {


player2 pl = new pl2 () ;


void OnTriggerEnter2D(Collider2D other){

    if(other.gameObject.tag == "Player"){
        other.gameObject.GetComponent<Player>().alive = false;
        Time.timeScale = 0; 
    }
}


void Start () {
    Time.timeScale = 1;

    pauseObjects = GameObject.FindGameObjectsWithTag("ShowOnPause");            //gets all objects with tag ShowOnPause
    finishObjects = GameObject.FindGameObjectsWithTag("ShowOnFinish");          //gets all objects with tag ShowOnFinish

    hidePaused();
    hideFinished();

    if(Application.loadedLevelName == "MainLevel")
        playerController = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>();
}


void Update () {

    if(Input.GetKeyDown(KeyCode.P)){
        if(Time.timeScale == 1 && player.alive == true){
            Time.timeScale = 0;
            showPaused();
        } else if (Time.timeScale == 0 && player.alive == true){
            Time.timeScale = 1;
            hidePaused();
        }
    }
}

public void Reload(){
    Application.LoadLevel(Application.loadedLevel);
}


public void pauseControl(){
    if(Time.timeScale == 1){
        Time.timeScale = 0;
        showPaused();
    } else if (Time.timeScale == 0){
        Time.timeScale = 1;
        hidePaused();
    }
}

public void showPaused(){
    foreach(GameObject g in pauseObjects){
        g.SetActive(true);
    }
}

//hides objects with ShowOnPause tag
public void hidePaused(){
    foreach(GameObject g in pauseObjects){
        g.SetActive(false);
    }
}

//shows objects with ShowOnFinish tag
public void showFinished(){
    foreach(GameObject g in finishObjects){
        g.SetActive(true);
    }
}

//hides objects with ShowOnFinish tag
public void hideFinished(){
    foreach(GameObject g in finishObjects){
        g.SetActive(false);
    }
}

//loads inputted level
public void LoadLevel(string level){
    Application.LoadLevel(level);
}       



GameObject [] pauseObjects;
GameObject [] finishObjects;
player2 Player;

}


}
2
  • agradeço muito a ajuda obrigado! Commented 14/09/2017 às 22:07
  • quando puder testarei, que vou viajar testarei, mas a principio estava fazendo uns testes e me esqueci de de por a classe dentro, agradeço por ter se dedicado a a ajudar. Commented 14/09/2017 às 22:19

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .