Esempio n. 1
0
    void hitByRayCast(GameObject hit)
    {
        //Debug.Log("hitByRayCast");

        if (hit.layer == gameObject.layer)
        {
            StartCoroutine(damagedAnim());

            if (Application.loadedLevel == 2)
            {
                stats.health -= DBAccess.instance.userPrefs.userGun.modifiedPower;
            }

            if (stats.health > 0)
            {
                if (onEnemyStatsChange != null)
                {
                    onEnemyStatsChange(stats, EnemyState);
                }
            }
            else
            {
                if (Application.platform == RuntimePlatform.IPhonePlayer)
                {
                    ChartBoostBinding.trackEvent("Player Win");
                }

                EnemyState = _EnemyState.Dead;

                StopAllCoroutines();

                mat.color = Color.white;

                iTween.Stop(gameObject);
                iTween.Stop(enemyActual);

                enemyActual.animation.Stop();
                enemyActual.animation.Play("Character_Death");

                if (onEnemyStatsChange != null)
                {
                    onEnemyStatsChange(stats, EnemyState);
                }

                GameObject.Find("Crosshair").GetComponent <UISprite>().enabled = false;
            }

            // If in Tutorial Level
            if (Application.loadedLevel == 1)
            {
                // Reset state of tutorial to progress forward
                Tutorial t = GameObject.Find("Player").GetComponent <Tutorial>();

                if (hitCount < 4 && (int)t.TutorialState < (int)Tutorial._TutorialState.MissionFour)
                {
                    hitCount++;
                }
                else if (t.TutorialState == Tutorial._TutorialState.MissionFour)
                {
                    hitCount++;

                    stats.health -= 10;

                    if (stats.health > 0)
                    {
                        if (onEnemyStatsChange != null)
                        {
                            onEnemyStatsChange(stats, EnemyState);
                        }
                    }
                    else
                    {
                        EnemyState = _EnemyState.Dead;

                        StopAllCoroutines();

                        mat.color = Color.white;

                        iTween.Stop(gameObject);
                        iTween.Stop(enemyActual);

                        enemyActual.animation.Stop();
                        enemyActual.animation.Play("Character_Death");

                        TutorialGrid tg = GameObject.FindObjectOfType(typeof(TutorialGrid)) as TutorialGrid;
                        tg.moveGrid(Tutorial._TutorialState.None);

                        if (onEnemyStatsChange != null)
                        {
                            onEnemyStatsChange(stats, EnemyState);
                        }
                    }
                }
                else
                {
                    // Reset hitCount for reuse through tutorial
                    hitCount = 0;

                    t.axes = Tutorial.RotationAxes.None;
                    t.grid.moveGrid(Tutorial._TutorialState.None);

                    // Stop AI pathing
                    GetComponent <AStarEnemy>().StopAllCoroutines();
                }
            }
        }
    }
Esempio n. 2
0
    void hitByRayCast(GameObject hit) 
	{ 
		//Debug.Log("hitByRayCast");
		
		if( hit.layer == gameObject.layer )
		{
			StartCoroutine(damagedAnim()); 
			
			if( Application.loadedLevel == 2 )
				stats.health -= DBAccess.instance.userPrefs.userGun.modifiedPower;
			
			if( stats.health > 0 )
			{				
				if( onEnemyStatsChange != null )
					onEnemyStatsChange(stats, EnemyState);
			} else {
				if( Application.platform == RuntimePlatform.IPhonePlayer )
					ChartBoostBinding.trackEvent( "Player Win" );
				
				EnemyState = _EnemyState.Dead;
				
				StopAllCoroutines();
				
				mat.color = Color.white;
				
				iTween.Stop(gameObject);
				iTween.Stop(enemyActual);
				
				enemyActual.animation.Stop();
				enemyActual.animation.Play("Character_Death");
				
				if( onEnemyStatsChange != null )
					onEnemyStatsChange(stats, EnemyState);
				
				GameObject.Find("Crosshair").GetComponent<UISprite>().enabled = false;
			}
			
			// If in Tutorial Level
			if( Application.loadedLevel == 1 )
			{
				// Reset state of tutorial to progress forward
				Tutorial t = GameObject.Find("Player").GetComponent<Tutorial>();
				
				if( hitCount < 4 && (int)t.TutorialState < (int)Tutorial._TutorialState.MissionFour )
					hitCount++;
				else if( t.TutorialState == Tutorial._TutorialState.MissionFour )
				{
					hitCount++;
					
					stats.health -= 10;
					
					if( stats.health > 0 )
					{				
						if( onEnemyStatsChange != null )
							onEnemyStatsChange(stats, EnemyState);
					} else {
						EnemyState = _EnemyState.Dead;
						
						StopAllCoroutines();
						
						mat.color = Color.white;
						
						iTween.Stop(gameObject);
						iTween.Stop(enemyActual);
						
						enemyActual.animation.Stop();
						enemyActual.animation.Play("Character_Death");
						
						TutorialGrid tg = GameObject.FindObjectOfType( typeof( TutorialGrid ) ) as TutorialGrid;
						tg.moveGrid(Tutorial._TutorialState.None);
						
						if( onEnemyStatsChange != null )
							onEnemyStatsChange(stats, EnemyState);
					}
				}
				else
				{
					// Reset hitCount for reuse through tutorial
					hitCount = 0;
					
					t.axes = Tutorial.RotationAxes.None;
					t.grid.moveGrid(Tutorial._TutorialState.None);
					
					// Stop AI pathing
					GetComponent<AStarEnemy>().StopAllCoroutines();
				}
			}
		}
	}