Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
avatar image
0
Question by SeanWink · Jan 02, 2018 at 12:41 AM · playerprefstaggameobjectsload sceneplayer settings

how can I tag a gameobject as Player at the start of a scene loading from the last?

I need to tag a gameobject the player selects from a character selection screen from the last scene in the next scene.

Comment
Add comment · Show 2
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 SeanWink · Jan 02, 2018 at 12:52 AM 0
Share

Can I do something like

Start Playerpref.SetTag= "Player"

avatar image David_Rios SeanWink · Jan 02, 2018 at 03:52 AM 0
Share

From my knowledge, something like that is not possible.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by David_Rios · Jan 02, 2018 at 03:51 AM

With assumption that you're using default Unity UI buttons, you can use the OnClick function with a referenced script to change the player's tag. The code would go like this; This includes referencing the player. I will show two separate functions giving the player different tags based on if they were selected or not.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class TagScript : MonoBehaviour {

     //GameObject you want as player
     public GameObject Player;
     
     public void WarriorTag() 
     {
        Player.tag = "Warrior";
     }
     
     public void MageTag() 
     {
        Player.tag = "Mage";
     }
 }

If you reference this script through the OnClick function and select the function representing the button, this should work fine. If you don't know how to do this, comment below. This will tag the GameObject the player selects if there are UI buttons on the selection screen. If they are objects that are to be chosen, then different code will be needed.

Comment
Add comment · Show 3 · 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 SeanWink · Jan 02, 2018 at 07:55 AM 0
Share

Will this require the player to press a button to tag? I already programmed the character selection. The player selects a character then it loads the scene and saves the selection in the Playerpref. Could I add a line of code in this script that says to "tag the player's selection " so the next scene makes that object the Player and all my scripts work fine because they need to find the player? All my scripts work fine when I manually toggle the player tag on the object I just need it to happen when the scene loads.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Scene$$anonymous$$anagement;

 public class CharacterSelection : $$anonymous$$onoBehaviour {
 
     private GameObject[] characterList;
     private int index; // keeping track of which model we are looking at
     //Get reference to every single object/ character
     private void Start ()
     {
         index = PlayerPrefs.GetInt ("CharacterSelected");
         characterList = new GameObject[transform.childCount];
 
         // Fill the array with our models
         for (int i = 0; i < transform.childCount; i++)
             characterList [i] = transform.GetChild (i).gameObject;
         // We toggle off their renderer
         foreach (GameObject go in characterList)
             go.SetActive (false);
         // we togggle on the selected Character
         if (characterList [index])
             characterList [index].SetActive (true);
         
     }
     public void ToggleLeft()
     {
         // Toggle off the current model
         characterList[index].SetActive(false); // turning off index  object
 
         index --; // Or you could write index --; or index= index -1;
         if (index < 0)
         index = characterList.Length - 1; // security check to see if we are not out of array range. This brings you back to end of index 
 
         // toggle on the  current model
         characterList[index].SetActive(true);// turnning ON index object
     }
     public void ToggRight()
     {
         // Toggle off the current model
         characterList[index].SetActive(false); // turning off index  object
 
         index ++; // Or you could write index --; or index= index -1;
         if (index == characterList.Length)
             index = 0; // security check to see if we are not out of array range. This brings you back to end of index 
 
         // toggle on the  current model
         characterList[index].SetActive(true);// turnning ON index object
     }
 
     public void ChangeSceneButton() // public functions because we call them from buttons
     {
         PlayerPrefs.SetInt ("CharacterSelected", index); // transfer charect date to next scene by storing character information in a prefab
         Scene$$anonymous$$anager.LoadScene ("Gameplay lvl");
 
     }
 }
 
avatar image SeanWink · Jan 02, 2018 at 08:47 AM 0
Share

Or maybe I could say that the objects in my array are "player" something like Player.tag= "CharacterList" in the script?

avatar image David_Rios SeanWink · Jan 04, 2018 at 12:38 AM 0
Share

What gameobject's tag are you trying to change? What is the gameObject's name in the script?

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.

Follow this Question

Answers Answers and Comments

74 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

Related Questions

If I have an exiting player object setup how do I give the players selected character the game objects properties in the next level. 1 Answer

CompareTag to multiple GameObjects 1 Answer

How To Select Single Object From All Objects We Found Whit Tag? 1 Answer

How to save playerprefs data into Google PlayGames (unity) plugin? 0 Answers

Can someone tell me what is wrong with this? 2 Answers


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