Search Unity

2d Character Selector...

Discussion in 'Scripting' started by shawnrevels, Aug 31, 2015.

  1. shawnrevels

    shawnrevels

    Joined:
    Aug 13, 2014
    Posts:
    86
    Ok so i have a game that has One character. 2D character to be exact. He has a simple sprite sheet that has 5 sprites attached. Simple run animation, with two singled out sprites that are for idle. So everything works fine with him.

    I have a bunch of other 2D characters that i would like to add to the game. So lets say from the main menu my player can select Shop from the main menu and then open up the shop menu scene and choose what character thet want to play with. Once chosen than that player will be played in the game. I have two characters in my game now. I made the shop scene... I made two buttons.. On is Char 1 and the other Char 2.. I have a script which is character selector... Which is this..

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class characterselect : MonoBehaviour {
    5.  
    6.     public GameObject sprite1; // Drag your first sprite here
    7.     public GameObject sprite2; // Drag your second sprite here
    8.  
    9.     public int player;
    10.     public int player2;
    11.  
    12. void Start ()
    13. {
    14.    
    15.     player = PlayerPrefs.GetInt ("CurrentPlayer");
    16.     player = PlayerPrefs.GetInt ("CurrentPlayer1");
    17.    
    18. }
    19.  
    20.  
    21.  
    22. public void getSprite1 ()
    23. {
    24.    
    25.  
    26.    
    27.     sprite1.SetActive(true);
    28.     sprite2.SetActive(false);
    29.     PlayerPrefs.SetInt ("CurrentPlayer", player);
    30.        
    31.    
    32. }
    33.  
    34.     public void getSprite2()
    35.     {
    36.    
    37.     sprite1.SetActive(true);
    38.     sprite2.SetActive(false);
    39.    
    40.     PlayerPrefs.SetInt ("CurrentPlayer1", player2);  
    41.     }
    42. }
    Now mind you i'm crappy at Player Prefs so i'm not sure i even did that right. But i want the person playing to be able to quit the game and log back in and start off with what ever char they left with. I set the Game objects to the two sprites as you see above. The set active isnt working.. At all!!.. They both show up in the game. Any body know of a good 2d character selector..? Ive looked everwhere and cant find squat..
     
  2. shawnrevels

    shawnrevels

    Joined:
    Aug 13, 2014
    Posts:
    86
    I changed the sprite1.setactive to false in the getsprite2 function. That didnt do anything. I just noticed that was backwards.