void Awake() { sceneIndex = SceneManager.GetActiveScene().buildIndex; if (GM == null) { DontDestroyOnLoad(gameObject); GM = this; } else if (GM != this) { Destroy(gameObject); } up = (KeyCode)System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("p1UpKey", "W")); down = (KeyCode)System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("p1DownKey", "S")); left = (KeyCode)System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("p1LeftKey", "A")); right = (KeyCode)System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("p1RightKey", "D")); jump = (KeyCode)System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("p1JumpKey", "J")); attack = (KeyCode)System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("p1AttackKey", "K")); guard = (KeyCode)System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("p1GuardKey", "L")); projectile = (KeyCode)System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("p1ProjectileKey", "Space")); }
void Start() { controller = GetComponent <Controller2D>(); playerSprite = GetComponent <SpriteRenderer>(); playerIcon = GetComponentInChildren <SpriteRenderer>(); boxCollider = GetComponent <BoxCollider2D>(); respawnUp = GameObject.FindGameObjectWithTag("RespawnUp"); respawnDown = GameObject.FindGameObjectWithTag("RespawnDown"); respawnLeft = GameObject.FindGameObjectWithTag("RespawnLeft"); respawnRight = GameObject.FindGameObjectWithTag("RespawnRight"); if (gameObject.tag == "Player1") { opponent = GameObject.FindGameObjectWithTag("Player2"); } if (gameObject.tag == "Player2") { opponent = GameObject.FindGameObjectWithTag("Player1"); } activeAreaUp = GameObject.FindGameObjectWithTag("ActiveAreaUp"). GetComponent <BoxCollider2D>(); activeAreaDown = GameObject.FindGameObjectWithTag("ActiveAreaDown"). GetComponent <BoxCollider2D>(); activeAreaLeft = GameObject.FindGameObjectWithTag("ActiveAreaLeft"). GetComponent <BoxCollider2D>(); activeAreaRight = GameObject.FindGameObjectWithTag("ActiveAreaRight"). GetComponent <BoxCollider2D>(); p1Script = GameObject.FindGameObjectWithTag("Player1"). GetComponent <Player1>(); p2Script = GameObject.FindGameObjectWithTag("Player2"). GetComponent <Player2>(); opponentSprite = opponent.GetComponent <SpriteRenderer>(); opponentIcon = opponent.GetComponentInChildren <SpriteRenderer>(); p1Score = GameObject.FindGameObjectWithTag("P1Score"). GetComponent <P1Score>(); p2Score = GameObject.FindGameObjectWithTag("P2Score"). GetComponent <P2Score>(); p1Win = p2Win = false; opponentSprite.enabled = true; opponentIcon.enabled = true; //p1WinCanvas = GameObject.FindGameObjectWithTag("P1Win"). GetComponent <Canvas>(); //p2WinCanvas = GameObject.FindGameObjectWithTag("P2Win"). GetComponent <Canvas>(); //p1WinCanvas.enabled = p2WinCanvas.enabled = false; killSound = GetComponents <AudioSource>()[0]; clingSound = GetComponents <AudioSource>()[1]; p1Hurtbox = GameObject.FindGameObjectWithTag("Player1"). GetComponent <PolygonCollider2D>(); p2Hurtbox = GameObject.FindGameObjectWithTag("Player2"). GetComponent <PolygonCollider2D>(); playerProjectileScript = GameObject.FindGameObjectWithTag("P1Projectile"). GetComponent <Projectile>(); opponentProjectileScript = GameObject.FindGameObjectWithTag("P2Projectile"). GetComponent <Projectile>(); gm = P1GameManager.GM; player = ReInput.players.GetPlayer(0); }
// Use this for initialization void Start() { sceneIndex = SceneManager.GetActiveScene().buildIndex; if (gameObject.tag == "P1Config") { p1Config = transform.Find("Buttons"); p1GM = P1GameManager.GM; waitingForKey = false; if (sceneIndex == 2) { for (int i = 0; i < p1Config.childCount; i++) { if (p1Config.GetChild(i).name == "UpButton") { p1Config.GetChild(i).GetComponentInChildren <Text>().text = p1GM.up.ToString(); } else if (p1Config.GetChild(i).name == "DownButton") { p1Config.GetChild(i).GetComponentInChildren <Text>().text = p1GM.down.ToString(); } else if (p1Config.GetChild(i).name == "LeftButton") { p1Config.GetChild(i).GetComponentInChildren <Text>().text = p1GM.left.ToString(); } else if (p1Config.GetChild(i).name == "RightButton") { p1Config.GetChild(i).GetComponentInChildren <Text>().text = p1GM.right.ToString(); } else if (p1Config.GetChild(i).name == "JumpButton") { p1Config.GetChild(i).GetComponentInChildren <Text>().text = p1GM.jump.ToString(); } else if (p1Config.GetChild(i).name == "AttackButton") { p1Config.GetChild(i).GetComponentInChildren <Text>().text = p1GM.attack.ToString(); } else if (p1Config.GetChild(i).name == "GuardButton") { p1Config.GetChild(i).GetComponentInChildren <Text>().text = p1GM.guard.ToString(); } else if (p1Config.GetChild(i).name == "ProjectileButton") { p1Config.GetChild(i).GetComponentInChildren <Text>().text = p1GM.projectile.ToString(); } } } } if (gameObject.tag == "P2Config") { p2Config = transform.Find("Buttons"); p2GM = P2GameManager.GM; waitingForKey = false; if (sceneIndex == 2) { for (int i = 0; i < p2Config.childCount; i++) { if (p2Config.GetChild(i).name == "UpButton") { p2Config.GetChild(i).GetComponentInChildren <Text>().text = p2GM.up.ToString(); } else if (p2Config.GetChild(i).name == "DownButton") { p2Config.GetChild(i).GetComponentInChildren <Text>().text = p2GM.down.ToString(); } else if (p2Config.GetChild(i).name == "LeftButton") { p2Config.GetChild(i).GetComponentInChildren <Text>().text = p2GM.left.ToString(); } else if (p2Config.GetChild(i).name == "RightButton") { p2Config.GetChild(i).GetComponentInChildren <Text>().text = p2GM.right.ToString(); } else if (p2Config.GetChild(i).name == "JumpButton") { p2Config.GetChild(i).GetComponentInChildren <Text>().text = p2GM.jump.ToString(); } else if (p2Config.GetChild(i).name == "AttackButton") { p2Config.GetChild(i).GetComponentInChildren <Text>().text = p2GM.attack.ToString(); } else if (p2Config.GetChild(i).name == "GuardButton") { p2Config.GetChild(i).GetComponentInChildren <Text>().text = p2GM.guard.ToString(); } else if (p2Config.GetChild(i).name == "ProjectileButton") { p2Config.GetChild(i).GetComponentInChildren <Text>().text = p2GM.projectile.ToString(); } } } } }