Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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 /
This question was closed Oct 07, 2019 at 09:08 AM by MOJAJA for the following reason:

used another way to solve

avatar image
0
Question by MOJAJA · Oct 01, 2019 at 08:39 AM · gamecharspellwordscramble

Word Spelling game ,how to add the letter to the word when click the button?

Hi all , I'm making a word spelling game , every words will have two blank. And there have four buttons that you can choose. When click the button will add the correct or wrong letter to the word. How to add a letter at a time and add a letter to the word ?

Like this: alt text

Letter.CS:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 
 public class Letter : MonoBehaviour
 {
     public char character;
     public RectTransform rectTransform;
     public Text text;
     public int index;
 
 
     public Letter Add(char c)
     {
         character = c;
         text.text = c.ToString();
         gameObject.SetActive(true);
         return this;
     }
 
 
 }

SpellGame.CS:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class SpellGame: MonoBehaviour
 {
     
     private DataCon dataCon;
     
     public char[] arr;
 
     public float space;
     public float lerpSpeed=5;
     public Transform parent;
     public Letter prefab;
     List<Letter> charObjects = new List<Letter>();
 
     public int currentWord;
 
     void Start()
     {
        
         dataCon = FindObjectOfType<DataCon>();
         ShowTo(currentWord);
     }
 
     public void ShowTo(int index)
     {
         arr =dataCon.allQuiz[0].questions[Random.Range(0,dataCon.allQuiz[0].questions.Length)].queText.ToCharArray();
         for (int i = 0; i < 2; i++)
         {
             arr[Random.Range(0,arr.Length)] = '_';
         }
 
         foreach (char c in arr)
         {
             Letter clone = Instantiate(prefab.gameObject).GetComponent<Letter>();
             clone.transform.SetParent(parent);
 
             charObjects.Add(clone.Add(c));
         }
         currentWord = index;
        
     }
 
    
 
 
     void RepositionObject()
     {
         if (charObjects.Count == 0)
         {
             return;
         }
 
         float center = (charObjects.Count - 0.9f) / 2;
         for (int i = 0; i < charObjects.Count; i++)
         {
             charObjects[i].rectTransform.anchoredPosition = Vector2.Lerp(charObjects[i].rectTransform.anchoredPosition, new Vector2((i - center) * space, 0), lerpSpeed * Time.deltaTime);
             charObjects[i].index = i;
         }
     }
 
    
     void Update()
     {
         RepositionObject();
        
     }
 
 
 }


AddButton.CS:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class AddButton: MonoBehaviour
 {
     public Text text;
 
     private WordGame wordGame;
     private Letter letter;
 
 
     private void Start()
     {
         wordGame = FindObjectOfType<WordGame>();
         letter = FindObjectOfType<Letter>();
     }
 
 
     public void ClickButton()
     {
 
         char[] c = text.text.ToCharArray();
         
         for (int i = 0; i < wordGame.arr.Length; i++)
         {
             if (wordGame.arr[i]=='_')
             {
                 wordGame.arr[i] = c[0];
                 letter.character = c[0];
                
             }
         }
 
 
     }
 
 
 }


01.png (9.4 kB)
Comment
Add comment
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

  • Sort: 
avatar image
0

Answer by rahul_95 · Oct 01, 2019 at 09:50 AM

If i got your question correct ,you are asking a way to put a letter at a certain place in a string if thats is the question ,have a script which holds the char index and the char value ,and attach it to the button,now every button has data of which index in that string can be set and know the value also

 public char charToPutInAString;
 public int indexOfChar;
 
 public void OnButtonClicked()
 {
 //first convert the string to char array 
 //set the stringArray[indexOfChar]=charToPutInAString;
 }
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 MOJAJA · Oct 03, 2019 at 04:15 AM -1
Share

Thank for your response, I used another way to solve. :)

Follow this Question

Answers Answers and Comments

147 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 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 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

getting udp package info inside unity (GlovePIE) 0 Answers

How do I optimize size of my unity word puzzle game? 3 Answers

link to open website 1 Answer

How to actually make an objective to my game 1 Answer

Some Ideas please? 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