• 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
0
Question by N00MKRAD · Sep 15, 2014 at 12:30 PM · error

[Solved] AutoType script doesn´t work!

(Maybe my English isn´t perfect) Hi, I want to use this script, but with the JS version I get an error and the CS version does nothing.

The error: "ToCharArray" is not a member of "Object"

 var letterPause = 0.2;
 var sound : AudioClip;
  
 private var word;
  
 function Start () {
     word = guiText.text;
     guiText.text = "";
     TypeText ();
 }
  
 function TypeText () {
     for (var letter in word.ToCharArray()) {
         guiText.text += letter;
         if (sound)
             audio.PlayOneShot (sound);
         yield WaitForSeconds (letterPause);
     }        
 }

And the CS version does nothing, the text will be displayed normally (Not letter by letter)

CS:

 using UnityEngine;
 using System.Collections;
  
 public class AutoType : MonoBehaviour {
  
     public float letterPause = 0.2f;
     public AudioClip sound;
  
     string message;
  
     // Use this for initialization
     void Start () {
         message = guiText.text;
         guiText.text = "";
         StartCoroutine(TypeText ());
     }
  
     IEnumerator TypeText () {
         foreach (char letter in message.ToCharArray()) {
             guiText.text += letter;
             if (sound)
                 audio.PlayOneShot (sound);
                 yield return 0;
             yield return new WaitForSeconds (letterPause);
         }      
     }
 }


Thanks in advance...

Comment
Add comment · Show 3
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 gjf · Sep 15, 2014 at 12:41 PM 0
Share

take a look at this which has helped others in the past.

avatar image Zodiarc · Sep 15, 2014 at 12:44 PM 0
Share

If you would say what error exactly you get maybe it would be easier for us to help.

avatar image N00MKRAD · Sep 15, 2014 at 04:02 PM 0
Share

Sorry, I forgot to write what line the error is. Im not on my Computer at the momen, I'll post it later

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by zharik86 · Sep 15, 2014 at 07:02 PM

Javascript doesn't have the concept of chars. Just use strings. I change little your JS script:

  var letterPause = 0.2;
  var sound : AudioClip;
 
  private var word: String; //declare type
 
  function Start () {
   word = guiText.text;
   guiText.text = "";
   TypeText ();
  }
 
  function TypeText () {
   for(var i: int = 0; i < word.Length; i++) {
    guiText.text += word.Substring(i, 1);
    if (sound)
     audio.PlayOneShot (sound);
    yield WaitForSeconds (letterPause);
   }       
  }

I hope that it will help you.

Comment
Add comment · Show 1 · 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 N00MKRAD · Sep 16, 2014 at 06:31 PM 0
Share

Thank you!

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

24 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

Related Questions

The referenced script on this Behaviour is missing! 0 Answers

Shooting script issue? 0 Answers

need help, with greater than statment 1 Answer

syntax errors 1 Answer

I need help with the eval() function of javascrit 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges