Noticias

¡RECUERDA QUE SI ERES UN NUEVO USUARIO, DEBES PRESENTARTE PARA PODER PUBLICAR MENSAJES! | TENEMOS CANAL OFICIAL DE TELEGRAM: t.me/unity3dspain

Problema OnTriggerEnter2D Dialogo NPC´S

Iniciado por vigesimo, Marzo 27, 2017, 04:29:33 AM

Tema anterior - Siguiente tema
Marzo 27, 2017, 04:29:33 AM Ultima modificación: Marzo 27, 2017, 12:30:31 PM por pioj
Buenas a todos, mi problema en el que me quede estancado es sobre un sistema dedialogos que usa " public AssetText text " para colocar mi texto text.txt
 
Por ejemplo tenemos 2 NPC o 3(gameObject), a cada uno le asignamos  un text.txt  con su dialogo en su interior y una collision 2d trigger, en el que el player cuando se acerca y luego apretamos espacio se muestra el dialogo, hasta ahi todo perfecto, pero el problema es que al activar uno me sale el dialogo de otro npc y me acero a otro npc y me sale el mismo dialogo, los 3 npc me sale el mismo dialogo siendo que le asigne diferentes textos
 
 
 
este es el que atacho a los npc
 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class ActivateTextAtLine : MonoBehaviour {
 
public TextAsset theText;
public int startLine;
public int endLine;
public textBoxManager theTextBox;
public bool destroyWhenActivate;
public bool requireButtomPress;
public static bool waitForPress;
 
public string nombreNpc;
 
// Use this for initialization
void Start () {
   theTextBox = FindObjectOfType<textBoxManager> ();
}

// Update is called once per frame
void Update () {
   
   if (waitForPress && Input.GetKeyDown(KeyCode.Space)) {
      
      waitForPress = false;
      theTextBox.ReloadScripts (theText);
      theTextBox.currentLine = startLine;
      theTextBox.endAtLine = endLine;
      //theTextBox.EnableTextBox ();
 
      if (destroyWhenActivate) {
         Destroy (gameObject);
      }
 
   }
      
}
void OnTriggerEnter2D(Collider2D other)
{
   
   if (other.gameObject.name == "Player") {
      
         if (requireButtomPress) {
            waitForPress = true;
            return;
         }
 
         theTextBox.ReloadScripts (theText);
         theTextBox.currentLine = startLine;
         theTextBox.endAtLine = endLine;
         theTextBox.EnableTextBox ();
         if (destroyWhenActivate) {
            Destroy (gameObject);
      
         }
      }
   }
   
   
   void OnTriggerExit2D(Collider2D other)
{
 
   if (other.name == "Player") {
         waitForPress = false;
      }
   }
}

 
 
 
 
 
y este el manager, motor de dialogo
 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class textBoxManager : MonoBehaviour {
public TextAsset textFile;
public GameObject textBox;
public Text theText;
public int currentLine;
public int endAtLine;
public movement player;
public bool isActive;
public bool stopPlayerMovement;
 
public string[] textLines;
// Use this for initialization
void Start () {
   player = FindObjectOfType<movement> ();
   if (textFile != null) {
      textLines = (textFile.text.Split('\n'));
   }
   if (endAtLine == ) {
      endAtLine = textLines.Length - 1;
   }
   //theText.text = textLines [currentLine];
   if (isActive) {
      EnableTextBox ();
   } else {
      DisableTextBox ();
   }
}
void Update()
{
       
   if (!isActive) {
      return;   
   }
   theText.text = textLines [currentLine];
 
   if (currentLine > endAtLine) {
      
      DisableTextBox ();
      ActivateTextAtLine.waitForPress = true;
   
   } else {
      if (Input.GetKeyDown (KeyCode.Space)) {
      
         currentLine += 1;
      }
   }
          
}
public void EnableTextBox()
{
   textBox.SetActive (true);
   stopPlayerMovement = true;
   isActive = true;
   if(stopPlayerMovement){
      player.canMove = false;
   }
}
public void DisableTextBox()
{
   textBox.SetActive (false);
   stopPlayerMovement = false;
   isActive = false;
   if (!stopPlayerMovement) {
      player.canMove = true;
   }
}
public void ReloadScripts(TextAsset theText){
   if (theText != null) {
      textLines = new string[1];
      textLines = (theText.text.Split ('\n'));
      EnableTextBox ();
   }
}
}

 
no se que hacer, me gustaria que cada sea indivual para uno mismo y no se este mesclando dialogo entre npc.
 
 
 
gracias de antemano.

Etiquetas: