private void Start() { flickerScriptReference = GetComponent <FlickerScript>(); // flickerScriptReference //figure out how to access flicker variable from flickerScript //flickerScriptReference = gameObject.GetComponent<FlickerScript>(); flickerScriptReference.flicker = false; fireRate = Random.Range(0, 1); coll = GetComponent <Collider2D>(); _randomSpeed = Random.Range(minSpeed, maxSpeed); _playerReference = GameObject.Find("Player").GetComponent <Player>(); if (explosionAnim == null) { print("Enemy Animator Broken"); } if (_canFire == true) { InvokeRepeating("EnemyFireLaser", 0f, fireRate); } }
// Use this for initialization void Start() { gameManager = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameManager>(); player = GameObject.FindGameObjectWithTag("Player"); enemyFlicker = gameObject.GetComponent<FlickerScript>(); spriteMaterial = gameObject.GetComponent<SpriteRenderer>().material; enemyFlicker.SpriteMaterials.Add(spriteMaterial); }
// Use this for initialization void Start() { playerInput = InputManager.Instance; gameManager = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameManager>(); //Get all player child objects for easy access later. playerShoulder = gameObject.transform.FindChild("Player_Shoulder").gameObject; playerArm = gameObject.transform.FindChild("Player_Arm").gameObject; playerWeapon = playerArm.transform.FindChild("Weapon").gameObject; bulletSpawnPosX = playerArm.GetComponent<SpriteRenderer>().sprite.bounds.extents.x; playerFlicker = gameObject.GetComponent<FlickerScript>(); playerAnimScript = gameObject.GetComponent<AnimationScript>(); shoulderAnimScript = playerShoulder.GetComponent<AnimationScript>(); invincibilityTimer = new Timer(INVINCIBLE_TIME); //Subscribe to necessary events. playerInput.Key_Held += ProcessMovement; playerInput.Key_Released += Idle; playerInput.Key_Pressed += ProcessKeyPress; invincibilityTimer.OnTimerComplete += EndInvincibilityTime; gameManager.GameOverEvent += OnGameOver; crosshair = GameObject.Find("Crosshair"); //Populate the sprite materials with all sub-objects' materials. spriteMaterials.Add(gameObject.GetComponent<SpriteRenderer>().material); spriteMaterials.Add(playerShoulder.GetComponent<SpriteRenderer>().material); spriteMaterials.Add(playerArm.GetComponent<SpriteRenderer>().material); spriteMaterials.Add(playerWeapon.GetComponent<SpriteRenderer>().material); playerFlicker.SpriteMaterials = spriteMaterials; currDirectionVector = GlobalConstants.DOWN_VECTOR; }