游戏对象激活得太早
GameObject activates too soon
编辑
所以它就在这里,对此我毫不怀疑,但是为什么呢? NextOne.active = 真;无论是否按下操作按钮,都会发射。
if(Input.GetButtonDown("Action") && Op_3 == true)
{
AudioSource.PlayClipAtPoint(OptionsSound, transform.position);
Playerhealthscript.panic +=1;
print("1 works");
Option_3_SELECTED.active = false;
Option_4_Unselected.active = false;
Option_3_Unselected.active = false;
Option_4_SELECTED.active = false;
NextOne.active = true;
}
else if(Input.GetButtonDown("Action") && Op_4 == true)
{
AudioSource.PlayClipAtPoint(OptionsSound, transform.position);
Playerhealthscript.insanity +=1;
print("2 works");
Option_3_SELECTED.active = false;
Option_4_Unselected.active = false;
Option_3_Unselected.active = false;
Option_4_SELECTED.active = false;
NextOne.active = true;
}
按照我阅读本文的方式,如果按下操作按钮并且选项 3 或选项 4 处于活动状态,则应该发生以下情况:
播放一段音频 Playerhealth 脚本中的 Insanity 或 Panic 增加 1 在控制台中打印一条消息 Options 3 & 4 已停用 NextOne 已激活。
所以我在这里没有看到什么?为什么 NextOne 在按下或不按下操作时激活?我的语法错了吗?
编辑结束
让我告诉你我的脚本应该做什么:
出现一些文字。出现一个带有 A/B 选项的问题。您选择 A 或 B。这将激活一个具有类似脚本的游戏对象。该脚本会立即禁用您原来的脚本。您回答另一个 A/B 问题。 (这次来自新脚本,因为旧脚本已被停用)一旦您回答了第二个问题(新脚本中只有一个),第三个 GameOBject 将激活,再次使用另一个类似的脚本,结果相同。这是一个链条。所以基本上它会
游戏对象 1 在场景开始时处于活动状态。 (Script1) A/B 选择 GameObject 1 被停用 GameObject 2 被激活(Script2) New A/B 选择 GameObject3 被激活(Script3) 等等。
它应该是一个简单的开/关开关脚本,但这是发生了什么:
当玩家做出第一个决定而不是从游戏对象 1 到游戏对象 2 时,脚本会绕过 2 并直接进入 3。这是从 1 到 2 的脚本:
//boolean variables
var Speaking : boolean = false;
var Entered : boolean = false;
var Speaking2 : boolean = false;
var Entered2 : boolean = false;
var Speaking3 : boolean = false;
var Entered3 : boolean = false;
var Speaking4 : boolean = false;
var Entered4 : boolean = false;
var Op_1 : boolean = false;
var Op_2 : boolean = false;
var Op_3 : boolean = false;
var Op_4 : boolean = false;
//speaking variables
var speakername : String;
var theselines : String;
var theselines2 : String;
var theselines3 : String;
var theselines4 : String;
var theselines5 : String;
var these2lines : String;
var these2lines2 : String;
var these2lines3 : String;
var these2lines4 : String;
var these2lines5 : String;
var these3lines : String;
var these3lines2 : String;
var these3lines3 : String;
var these3lines4 : String;
var these3lines5 : String;
var these4lines : String;
var these4lines2 : String;
var these4lines3 : String;
//other variables
var Background : GameObject;
var Option_1_Unselected : GameObject;
var Option_2_Unselected : GameObject;
var Option_1_SELECTED : GameObject;
var Option_2_SELECTED : GameObject;
var NextOne : GameObject;
var MouseLookScript : MouseLook;
public var guiSkin : GUISkin;
var OptionsSound : AudioClip;
var MoveSound : AudioClip;
var Playerhealthscript : Playerhealth;
function Start () {
Entered = true;
}
function Continued(){
yield WaitForSeconds(0.25);
Entered = false;
Speaking = false;
Entered2 = true;
}
function Continued2(){
yield WaitForSeconds(0.25);
Entered2 = false;
Speaking2 = false;
Entered3 = true;
}
function Continued3(){
yield WaitForSeconds(0.25);
Entered3 = false;
Speaking3 = false;
Entered4 = true;
}
function OnGUI(){
if(Entered){
Background.active = true;
MouseLookScript.enabled = false;
Speaking = true;
GUI.skin = guiSkin;
GUI.Label(Rect(410,295,400,175), speakername);
GUI.Label(Rect(500,345,400,175), theselines);
GUI.Label(Rect(500,380,400,175), theselines2);
GUI.Label(Rect(500,415,400,175), theselines3);
GUI.Label(Rect(500,455,400,175), theselines4);
GUI.Label(Rect(500,495,400,175), theselines5);
if(Input.GetButtonDown("Action")){
Continued();
}
}
if(Entered2){
Speaking2 = true;
GUI.skin = guiSkin;
GUI.Label(Rect(410,295,400,175), speakername);
GUI.Label(Rect(500,345,400,175), these2lines);
GUI.Label(Rect(500,380,400,175), these2lines2);
GUI.Label(Rect(500,415,400,175), these2lines3);
GUI.Label(Rect(500,455,400,175), these2lines4);
GUI.Label(Rect(500,495,400,175), these2lines5);
if(Input.GetButtonDown("Action")){
Continued2();
}
}
if(Entered3){
Speaking3 = true;
GUI.skin = guiSkin;
GUI.Label(Rect(410,295,400,175), speakername);
GUI.Label(Rect(500,345,400,175), these3lines);
GUI.Label(Rect(500,380,400,175), these3lines2);
GUI.Label(Rect(500,415,400,175), these3lines3);
GUI.Label(Rect(500,455,400,175), these3lines4);
GUI.Label(Rect(500,495,400,175), these3lines5);
if(Input.GetButtonDown("Action")){
Continued3();
}
}
//Question_1
if(Entered4)
{
Speaking4 = true;
GUI.skin = guiSkin;
GUI.Label(Rect(410,295,400,175), speakername);
GUI.Label(Rect(415,345,400,175), these4lines);
GUI.Label(Rect(415,380,400,175), these4lines2);
GUI.Label(Rect(415,415,400,175), these4lines3);
Option_1_SELECTED.active = true;
Option_2_Unselected.active = true;
Option_1_Unselected.active = false;
Option_2_SELECTED.active = false;
Op_1 = true;
Op_2 = false;
if(Input.GetAxis("Vertical") < -.5)
{
Option_1_SELECTED.active = false;
Option_2_Unselected.active = false;
Option_1_Unselected.active = true;
Option_2_SELECTED.active = true;
Op_1 = false;
Op_2 = true;
print("this works");
}
if(Input.GetButtonDown("Action") && Op_1 == true)
{
AudioSource.PlayClipAtPoint(OptionsSound, transform.position);
Playerhealthscript.panic +=1;
print("1 works");
Option_1_SELECTED.active = false;
Option_2_Unselected.active = false;
Option_1_Unselected.active = false;
Option_2_SELECTED.active = false;
NextOne.active = true;
}
else if(Input.GetButtonDown("Action") && Op_2 == true)
{
AudioSource.PlayClipAtPoint(OptionsSound, transform.position);
Playerhealthscript.insanity +=1;
print("2 works");
Option_1_SELECTED.active = false;
Option_2_Unselected.active = false;
Option_1_Unselected.active = false;
Option_2_SELECTED.active = false;
NextOne.active = true;
}
}
}
我认为这应该可以解决问题,所以我认为问题出在 2 到 3 的脚本中。下面是 2 到 3 的脚本。
#pragma strict
//boolean variables
var Speaking5 : boolean = false;
var Entered5 : boolean = false;
var Op_3 : boolean = false;
var Op_4 : boolean = false;
//speaking variables
var speakername : String;
var these5lines : String;
var these5lines2 : String;
var these5lines3 : String;
//other variables
var Background : GameObject;
var Option_3_Unselected : GameObject;
var Option_4_Unselected : GameObject;
var Option_3_SELECTED : GameObject;
var Option_4_SELECTED : GameObject;
var OldOne : GameObject;
var NextOne : GameObject;
var MouseLookScript : MouseLook;
public var guiSkin : GUISkin;
var OptionsSound : AudioClip;
var MoveSound : AudioClip;
var Playerhealthscript : Playerhealth;
function Start () {
OldOne.active = false;
NextOne.active = false;
Entered5 = true;
}
function OnGUI(){
if(Entered5)
{
Speaking5 = true;
GUI.skin = guiSkin;
GUI.Label(Rect(410,295,400,175), speakername);
GUI.Label(Rect(415,345,400,175), these5lines);
GUI.Label(Rect(415,380,400,175), these5lines2);
GUI.Label(Rect(415,415,400,175), these5lines3);
Option_3_SELECTED.active = true;
Option_4_Unselected.active = true;
Option_3_Unselected.active = false;
Option_4_SELECTED.active = false;
Op_3 = true;
Op_4 = false;
if(Input.GetAxis("Vertical") < -.5)
{
Option_3_SELECTED.active = false;
Option_4_Unselected.active = false;
Option_3_Unselected.active = true;
Option_4_SELECTED.active = true;
Op_3 = false;
Op_4 = true;
print("this works");
}
if(Input.GetButtonDown("Action") && Op_3 == true)
{
AudioSource.PlayClipAtPoint(OptionsSound, transform.position);
Playerhealthscript.panic +=1;
print("1 works");
Option_3_SELECTED.active = false;
Option_4_Unselected.active = false;
Option_3_Unselected.active = false;
Option_4_SELECTED.active = false;
NextOne.active = true;
}
else if(Input.GetButtonDown("Action") && Op_4 == true)
{
AudioSource.PlayClipAtPoint(OptionsSound, transform.position);
Playerhealthscript.insanity +=1;
print("2 works");
Option_3_SELECTED.active = false;
Option_4_Unselected.active = false;
Option_3_Unselected.active = false;
Option_4_SELECTED.active = false;
NextOne.active = true;
}
}
}
知道了!我儿子指出,我需要做的就是每回答一个问题就加一个整数,然后将该整数作为继续下一个问题的条件。
#pragma strict
//boolean variables
var Speaking5 : boolean = false;
var Entered5 : boolean = false;
var Op_3 : boolean = false;
var Op_4 : boolean = false;
var Question : int = 0;
//speaking variables
var speakername : String;
var addhealth : String;
var addhealth2 : String
var these5lines : String;
var these5lines2 : String;
var these5lines3 : String;
//other variables
var Background : GameObject;
var Option_3_Unselected : GameObject;
var Option_4_Unselected : GameObject;
var Option_3_SELECTED : GameObject;
var Option_4_SELECTED : GameObject;
var OldOne : GameObject;
var NextOne : GameObject;
var MouseLookScript : MouseLook;
public var guiSkin : GUISkin;
var OptionsSound : AudioClip;
var MoveSound : AudioClip;
var Playerhealthscript : Playerhealth;
function Update(){
if(Question >= 1)
{
NextOne.active = true;
}
}
function Start () {
OldOne.active = false;
//NextOne.active = false;
Entered5 = true;
}
function OnGUI(){
if(Entered5)
{
Speaking5 = true;
GUI.skin = guiSkin;
GUI.Label(Rect(410,295,400,175), speakername);
GUI.Label(Rect(415,345,400,175), these5lines);
GUI.Label(Rect(415,380,400,175), these5lines2);
GUI.Label(Rect(415,415,400,175), these5lines3);
Option_3_SELECTED.active = true;
Option_4_Unselected.active = true;
Option_3_Unselected.active = false;
Option_4_SELECTED.active = false;
Op_3 = true;
Op_4 = false;
if(Input.GetAxis("Vertical") < -.5)
{
Option_3_SELECTED.active = false;
Option_4_Unselected.active = false;
Option_3_Unselected.active = true;
Option_4_SELECTED.active = true;
Op_3 = false;
Op_4 = true;
print("this works");
}
if(Input.GetButtonDown("Action") && Op_3 == true)
{
AudioSource.PlayClipAtPoint(OptionsSound, transform.position);
Playerhealthscript.panic +=1;
print("1 works");
Question += 1;
Option_3_SELECTED.active = false;
Option_4_Unselected.active = false;
Option_3_Unselected.active = false;
Option_4_SELECTED.active = false;
}
else if(Input.GetButtonDown("Action") && Op_4 == true)
{
AudioSource.PlayClipAtPoint(OptionsSound, transform.position);
Playerhealthscript.insanity +=1;
print("2 works");
Question += 1;
Option_3_SELECTED.active = false;
Option_4_Unselected.active = false;
Option_3_Unselected.active = false;
Option_4_SELECTED.active = false;
}
}
}
编辑
所以它就在这里,对此我毫不怀疑,但是为什么呢? NextOne.active = 真;无论是否按下操作按钮,都会发射。
if(Input.GetButtonDown("Action") && Op_3 == true)
{
AudioSource.PlayClipAtPoint(OptionsSound, transform.position);
Playerhealthscript.panic +=1;
print("1 works");
Option_3_SELECTED.active = false;
Option_4_Unselected.active = false;
Option_3_Unselected.active = false;
Option_4_SELECTED.active = false;
NextOne.active = true;
}
else if(Input.GetButtonDown("Action") && Op_4 == true)
{
AudioSource.PlayClipAtPoint(OptionsSound, transform.position);
Playerhealthscript.insanity +=1;
print("2 works");
Option_3_SELECTED.active = false;
Option_4_Unselected.active = false;
Option_3_Unselected.active = false;
Option_4_SELECTED.active = false;
NextOne.active = true;
}
按照我阅读本文的方式,如果按下操作按钮并且选项 3 或选项 4 处于活动状态,则应该发生以下情况:
播放一段音频 Playerhealth 脚本中的 Insanity 或 Panic 增加 1 在控制台中打印一条消息 Options 3 & 4 已停用 NextOne 已激活。
所以我在这里没有看到什么?为什么 NextOne 在按下或不按下操作时激活?我的语法错了吗?
编辑结束
让我告诉你我的脚本应该做什么:
出现一些文字。出现一个带有 A/B 选项的问题。您选择 A 或 B。这将激活一个具有类似脚本的游戏对象。该脚本会立即禁用您原来的脚本。您回答另一个 A/B 问题。 (这次来自新脚本,因为旧脚本已被停用)一旦您回答了第二个问题(新脚本中只有一个),第三个 GameOBject 将激活,再次使用另一个类似的脚本,结果相同。这是一个链条。所以基本上它会 游戏对象 1 在场景开始时处于活动状态。 (Script1) A/B 选择 GameObject 1 被停用 GameObject 2 被激活(Script2) New A/B 选择 GameObject3 被激活(Script3) 等等。 它应该是一个简单的开/关开关脚本,但这是发生了什么: 当玩家做出第一个决定而不是从游戏对象 1 到游戏对象 2 时,脚本会绕过 2 并直接进入 3。这是从 1 到 2 的脚本:
//boolean variables
var Speaking : boolean = false;
var Entered : boolean = false;
var Speaking2 : boolean = false;
var Entered2 : boolean = false;
var Speaking3 : boolean = false;
var Entered3 : boolean = false;
var Speaking4 : boolean = false;
var Entered4 : boolean = false;
var Op_1 : boolean = false;
var Op_2 : boolean = false;
var Op_3 : boolean = false;
var Op_4 : boolean = false;
//speaking variables
var speakername : String;
var theselines : String;
var theselines2 : String;
var theselines3 : String;
var theselines4 : String;
var theselines5 : String;
var these2lines : String;
var these2lines2 : String;
var these2lines3 : String;
var these2lines4 : String;
var these2lines5 : String;
var these3lines : String;
var these3lines2 : String;
var these3lines3 : String;
var these3lines4 : String;
var these3lines5 : String;
var these4lines : String;
var these4lines2 : String;
var these4lines3 : String;
//other variables
var Background : GameObject;
var Option_1_Unselected : GameObject;
var Option_2_Unselected : GameObject;
var Option_1_SELECTED : GameObject;
var Option_2_SELECTED : GameObject;
var NextOne : GameObject;
var MouseLookScript : MouseLook;
public var guiSkin : GUISkin;
var OptionsSound : AudioClip;
var MoveSound : AudioClip;
var Playerhealthscript : Playerhealth;
function Start () {
Entered = true;
}
function Continued(){
yield WaitForSeconds(0.25);
Entered = false;
Speaking = false;
Entered2 = true;
}
function Continued2(){
yield WaitForSeconds(0.25);
Entered2 = false;
Speaking2 = false;
Entered3 = true;
}
function Continued3(){
yield WaitForSeconds(0.25);
Entered3 = false;
Speaking3 = false;
Entered4 = true;
}
function OnGUI(){
if(Entered){
Background.active = true;
MouseLookScript.enabled = false;
Speaking = true;
GUI.skin = guiSkin;
GUI.Label(Rect(410,295,400,175), speakername);
GUI.Label(Rect(500,345,400,175), theselines);
GUI.Label(Rect(500,380,400,175), theselines2);
GUI.Label(Rect(500,415,400,175), theselines3);
GUI.Label(Rect(500,455,400,175), theselines4);
GUI.Label(Rect(500,495,400,175), theselines5);
if(Input.GetButtonDown("Action")){
Continued();
}
}
if(Entered2){
Speaking2 = true;
GUI.skin = guiSkin;
GUI.Label(Rect(410,295,400,175), speakername);
GUI.Label(Rect(500,345,400,175), these2lines);
GUI.Label(Rect(500,380,400,175), these2lines2);
GUI.Label(Rect(500,415,400,175), these2lines3);
GUI.Label(Rect(500,455,400,175), these2lines4);
GUI.Label(Rect(500,495,400,175), these2lines5);
if(Input.GetButtonDown("Action")){
Continued2();
}
}
if(Entered3){
Speaking3 = true;
GUI.skin = guiSkin;
GUI.Label(Rect(410,295,400,175), speakername);
GUI.Label(Rect(500,345,400,175), these3lines);
GUI.Label(Rect(500,380,400,175), these3lines2);
GUI.Label(Rect(500,415,400,175), these3lines3);
GUI.Label(Rect(500,455,400,175), these3lines4);
GUI.Label(Rect(500,495,400,175), these3lines5);
if(Input.GetButtonDown("Action")){
Continued3();
}
}
//Question_1
if(Entered4)
{
Speaking4 = true;
GUI.skin = guiSkin;
GUI.Label(Rect(410,295,400,175), speakername);
GUI.Label(Rect(415,345,400,175), these4lines);
GUI.Label(Rect(415,380,400,175), these4lines2);
GUI.Label(Rect(415,415,400,175), these4lines3);
Option_1_SELECTED.active = true;
Option_2_Unselected.active = true;
Option_1_Unselected.active = false;
Option_2_SELECTED.active = false;
Op_1 = true;
Op_2 = false;
if(Input.GetAxis("Vertical") < -.5)
{
Option_1_SELECTED.active = false;
Option_2_Unselected.active = false;
Option_1_Unselected.active = true;
Option_2_SELECTED.active = true;
Op_1 = false;
Op_2 = true;
print("this works");
}
if(Input.GetButtonDown("Action") && Op_1 == true)
{
AudioSource.PlayClipAtPoint(OptionsSound, transform.position);
Playerhealthscript.panic +=1;
print("1 works");
Option_1_SELECTED.active = false;
Option_2_Unselected.active = false;
Option_1_Unselected.active = false;
Option_2_SELECTED.active = false;
NextOne.active = true;
}
else if(Input.GetButtonDown("Action") && Op_2 == true)
{
AudioSource.PlayClipAtPoint(OptionsSound, transform.position);
Playerhealthscript.insanity +=1;
print("2 works");
Option_1_SELECTED.active = false;
Option_2_Unselected.active = false;
Option_1_Unselected.active = false;
Option_2_SELECTED.active = false;
NextOne.active = true;
}
}
}
我认为这应该可以解决问题,所以我认为问题出在 2 到 3 的脚本中。下面是 2 到 3 的脚本。
#pragma strict
//boolean variables
var Speaking5 : boolean = false;
var Entered5 : boolean = false;
var Op_3 : boolean = false;
var Op_4 : boolean = false;
//speaking variables
var speakername : String;
var these5lines : String;
var these5lines2 : String;
var these5lines3 : String;
//other variables
var Background : GameObject;
var Option_3_Unselected : GameObject;
var Option_4_Unselected : GameObject;
var Option_3_SELECTED : GameObject;
var Option_4_SELECTED : GameObject;
var OldOne : GameObject;
var NextOne : GameObject;
var MouseLookScript : MouseLook;
public var guiSkin : GUISkin;
var OptionsSound : AudioClip;
var MoveSound : AudioClip;
var Playerhealthscript : Playerhealth;
function Start () {
OldOne.active = false;
NextOne.active = false;
Entered5 = true;
}
function OnGUI(){
if(Entered5)
{
Speaking5 = true;
GUI.skin = guiSkin;
GUI.Label(Rect(410,295,400,175), speakername);
GUI.Label(Rect(415,345,400,175), these5lines);
GUI.Label(Rect(415,380,400,175), these5lines2);
GUI.Label(Rect(415,415,400,175), these5lines3);
Option_3_SELECTED.active = true;
Option_4_Unselected.active = true;
Option_3_Unselected.active = false;
Option_4_SELECTED.active = false;
Op_3 = true;
Op_4 = false;
if(Input.GetAxis("Vertical") < -.5)
{
Option_3_SELECTED.active = false;
Option_4_Unselected.active = false;
Option_3_Unselected.active = true;
Option_4_SELECTED.active = true;
Op_3 = false;
Op_4 = true;
print("this works");
}
if(Input.GetButtonDown("Action") && Op_3 == true)
{
AudioSource.PlayClipAtPoint(OptionsSound, transform.position);
Playerhealthscript.panic +=1;
print("1 works");
Option_3_SELECTED.active = false;
Option_4_Unselected.active = false;
Option_3_Unselected.active = false;
Option_4_SELECTED.active = false;
NextOne.active = true;
}
else if(Input.GetButtonDown("Action") && Op_4 == true)
{
AudioSource.PlayClipAtPoint(OptionsSound, transform.position);
Playerhealthscript.insanity +=1;
print("2 works");
Option_3_SELECTED.active = false;
Option_4_Unselected.active = false;
Option_3_Unselected.active = false;
Option_4_SELECTED.active = false;
NextOne.active = true;
}
}
}
知道了!我儿子指出,我需要做的就是每回答一个问题就加一个整数,然后将该整数作为继续下一个问题的条件。
#pragma strict
//boolean variables
var Speaking5 : boolean = false;
var Entered5 : boolean = false;
var Op_3 : boolean = false;
var Op_4 : boolean = false;
var Question : int = 0;
//speaking variables
var speakername : String;
var addhealth : String;
var addhealth2 : String
var these5lines : String;
var these5lines2 : String;
var these5lines3 : String;
//other variables
var Background : GameObject;
var Option_3_Unselected : GameObject;
var Option_4_Unselected : GameObject;
var Option_3_SELECTED : GameObject;
var Option_4_SELECTED : GameObject;
var OldOne : GameObject;
var NextOne : GameObject;
var MouseLookScript : MouseLook;
public var guiSkin : GUISkin;
var OptionsSound : AudioClip;
var MoveSound : AudioClip;
var Playerhealthscript : Playerhealth;
function Update(){
if(Question >= 1)
{
NextOne.active = true;
}
}
function Start () {
OldOne.active = false;
//NextOne.active = false;
Entered5 = true;
}
function OnGUI(){
if(Entered5)
{
Speaking5 = true;
GUI.skin = guiSkin;
GUI.Label(Rect(410,295,400,175), speakername);
GUI.Label(Rect(415,345,400,175), these5lines);
GUI.Label(Rect(415,380,400,175), these5lines2);
GUI.Label(Rect(415,415,400,175), these5lines3);
Option_3_SELECTED.active = true;
Option_4_Unselected.active = true;
Option_3_Unselected.active = false;
Option_4_SELECTED.active = false;
Op_3 = true;
Op_4 = false;
if(Input.GetAxis("Vertical") < -.5)
{
Option_3_SELECTED.active = false;
Option_4_Unselected.active = false;
Option_3_Unselected.active = true;
Option_4_SELECTED.active = true;
Op_3 = false;
Op_4 = true;
print("this works");
}
if(Input.GetButtonDown("Action") && Op_3 == true)
{
AudioSource.PlayClipAtPoint(OptionsSound, transform.position);
Playerhealthscript.panic +=1;
print("1 works");
Question += 1;
Option_3_SELECTED.active = false;
Option_4_Unselected.active = false;
Option_3_Unselected.active = false;
Option_4_SELECTED.active = false;
}
else if(Input.GetButtonDown("Action") && Op_4 == true)
{
AudioSource.PlayClipAtPoint(OptionsSound, transform.position);
Playerhealthscript.insanity +=1;
print("2 works");
Question += 1;
Option_3_SELECTED.active = false;
Option_4_Unselected.active = false;
Option_3_Unselected.active = false;
Option_4_SELECTED.active = false;
}
}
}