• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by shepsaus000 · May 20, 2016 at 05:30 PM · scripting probleminstantiatetextclonefade

GUIText transition trouble

So I have a small, text-based cutscene that I have in my game, where the text fades when the player presses a button and new text instantly appears after three seconds. The fade and appearing aspects of my text are fine. It's just that I seem to have some trouble at the beginning of the cutscene: using UnityEngine; using System.Collections; using UnityEngine.UI; using UnityEngine.SceneManagement;

 public class Cutscene1Script : MonoBehaviour {
 
     public int cutsceneProgress;
     public bool startTimer;
     public bool noSpawn = true;
     public float cutsceneTransitionTimer = 3;
     public GUIText text;
 
     void Start (){
         noSpawn = false;
     }
     // Update is called once per frame
     void Update () {
 
         if (Input.GetButtonDown ("Fire1") && startTimer == false){
             startTimer = true;
 
         }
 
         if (startTimer == true) {
             cutsceneTransitionTimer -= Time.deltaTime;
         }
 
         if (cutsceneTransitionTimer <= 0) {
             cutsceneProgress += 1;
             cutsceneTransitionTimer = 3;
             startTimer = false;
             noSpawn = false;
         }
 
         if (cutsceneProgress == 1 && noSpawn == false) {
             Instantiate (text, new Vector3 (0.5f, 0.5f, 0), Quaternion.identity);
             text.text = "stuff";
             noSpawn = true;
             return;
         }
 
         if (cutsceneProgress == 2 && noSpawn == false) {
             Instantiate (text, new Vector3 (0.5f, 0.5f, 0), Quaternion.identity);
             noSpawn = true;
             text.text = "stuff2";
             return;
         }
         if (cutsceneProgress == 3 && noSpawn == false) {
             Instantiate (text, new Vector3 (0.5f, 0.5f, 0), Quaternion.identity);
             noSpawn = true;
             text.text = "stuff3";
             return;
         }
         if (cutsceneProgress == 4 && noSpawn == false) {
             Instantiate (text, new Vector3 (0.5f, 0.5f, 0), Quaternion.identity);
             noSpawn = true;
             text.text = "stuff4";
             return;
         }
         if (cutsceneProgress == 5 && noSpawn == false) {
             Instantiate (text, new Vector3 (0.5f, 0.5f, 0), Quaternion.identity);
             noSpawn = true;
             text.text = "stuff5";
             return;
         }
         if (cutsceneProgress == 6 && noSpawn == false) {
             Instantiate (text, new Vector3 (0.5f, 0.5f, 0), Quaternion.identity);
             noSpawn = true;
             text.text = "stuff6";
             return;
         }
         if (cutsceneProgress == 7 && noSpawn == false) {
             SceneManager.LoadScene ("NextScene");
             return;
         }
     }
 }
 

When the player first presses Fire1, the "stuff" text shows, w$$anonymous$$ch is what I want. The problem is that, on the next press, the same text shows up and then after a t$$anonymous$$rd press, it decides to change to "stuff2."

I t$$anonymous$$nk I have an idea on what is going on. Basically, after the GUIText fades, it gets destroyed and a clone is instantiated. I have a feeling the initial introduction of the clone is causing the problem, but I have no clue as to how to fix the problem.

One final note: t$$anonymous$$s script is on an empty gameObject, and the GUIText is defined as the initial object (it doesn't have (clone) on it via inspector).

Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by FortisVenaliter · May 20, 2016 at 05:37 PM

It's probably because cutsceneProgress starts at zero, but your first check is for if it equals one. Try decreasing your check numbers by one.

Comment

People who like this

0 Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image shepsaus000 · May 20, 2016 at 06:39 PM 0
Share

I did that and nothing is changing. I really think it's because of the introduction of a clone.

avatar image FortisVenaliter shepsaus000 · May 20, 2016 at 06:43 PM 0
Share

Ohhhh! I see the problem. When you set the text string, you're setting it on the prefab, not on the instantiated object. So, it will only work after the previous one was run. You need to get the instance back from the Instantiate call and apply your string to that, not to the 'text' prefab variable.

avatar image shepsaus000 FortisVenaliter · May 20, 2016 at 06:51 PM 0
Share

I see what you mean!...... but I don't know what to do to fix that :/

I'm still new to this whole unity thing. I'll see if I can't figure it out, but extra input would be appreciated :D

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

54 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Variable being shared between clones 2 Answers

cachedTextGenerator not working with instantiated canvas 1 Answer

How can I destroy an specific clone already instantiated, when there's more than one? 1 Answer

Instantiated Bullets Not Picking Up Correct Position/Rotation 2 Answers

Changing a variable on an instantiated prefab clone once created 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges