示例#1
0
    private void OnTriggerEnter2D(Collider2D collider)
    {
        //enemyAttack atkInfo = collider.GetComponentInParent<enemyAttack>();
        //如果是敌人的攻击则表现受击硬直
        if (collider.gameObject.tag == "enemy" && Time.time - status.LastAttackedTime > status.stiffTime)
        {
            status.IsAttacked = true;
            //enemyAttack atkInfo = collider.GetComponentInParent<enemyAttack>();
            enemyInfo einfo = collider.gameObject.GetComponent <enemyAttack>().E.GetComponent <enemyInfo>();

            status.UpdateBlood(-status.calculateDamage(einfo.thisInfo.AttackPower));

            if (!audio.isPlaying)
            {
                audio.PlayOneShot(attacked);
            }

            status.LastAttackedTime = Time.time;

            rigidbody2d.velocity = (tranform.position - collider.GetComponentInParent <Transform>().position) * status.moveSpeed;
        }

        if (collider.gameObject.tag == "collect" && Input.GetKeyDown(KeyCode.E))
        {
            enquire(collider.gameObject);
        }
    }
示例#2
0
	void OnTriggerEnter2D(Collider2D col){
		if (chef.attack && col.gameObject.tag == "Enemy") {
			enemy = col.gameObject.GetComponent<enemyInfo>();
			enemy.health -= chef.weaponDamage[chef.weaponChoice] * enemy.weaponDamage[chef.weaponChoice];
			
			if(col.gameObject.transform.position.x < this.transform.position.x) col.gameObject.rigidbody2D.velocity = new Vector2(-horKnockback, verKnockback);
			else col.gameObject.rigidbody2D.velocity = new Vector2(horKnockback, verKnockback);
		}
	}
示例#3
0
 void LoadScript()
 {
     isdie     = false;
     enemySA   = gameObject.GetComponent <SkeletonAnimation>();
     spManager = GameObject.Find("manager");
     info      = gameObject.GetComponent <enemyInfo>();
     target    = GameObject.Find("RoadManager");
     manager   = GameObject.Find("enemyManager");
     enemySA.skeleton.ScaleX = -Mathf.Abs(enemySA.skeleton.ScaleX);
 }
示例#4
0
    private void OnCollisionExit2D(Collision2D collision)
    {
        enemyInfo enemy = collision.gameObject.GetComponent <enemyInfo>();

        if (collision.gameObject.tag == "enemy")
        {
            SpriteRenderer sprite = GetComponent <SpriteRenderer>();
            sprite.color = Color.white;
        }
    }
示例#5
0
 public enemyInfo(enemyInfo clone)
 {
     startAfterSec = clone.startAfterSec;
     healthPoint   = clone.healthPoint;
     hitInterval   = clone.hitInterval;
     hitRange      = clone.hitRange;
     typeRed       = clone.typeRed;
     typeBlue      = clone.typeBlue;
     typeYellow    = clone.typeYellow;
     hitWaitSec    = clone.hitWaitSec;
     speed         = clone.speed;
 }
示例#6
0
 // Use this for initialization
 void Start()
 {
     childrenRender = GetComponentsInChildren <Renderer> ();
     for (int i = 0; i < childrenRender.Length; i++)
     {
         disappear.Add(childrenRender [i]);
     }
     originalMat  = GetComponentsInChildren <Renderer> () [0].material;
     myInfo       = new enemyInfo(controller_enableSituation.thisSit.level_assign[controller_enableSituation.thisSit.nowLevel].thisLevelEnemyInfo);
     agent.speed  = myInfo.speed;
     behaviourCor = StartCoroutine(behaviour());
     changeMat(originalMat);
 }
示例#7
0
 void Start()
 {
     isAttack       = false;
     lastAttackTime = 0.0f;
     seeker         = GetComponent <Seeker>();
     rigidbody2d    = GetComponent <Rigidbody2D>();
     collider       = GetComponent <Collider2D>();
     einfo          = GetComponent <enemyInfo>();
     //生成怪物时需在这里把类型替换成想要的类型
     //einfo.changeEnemyType(enemyInfo.Type.witcher);
     lastAttackedTime = 0.0f;
     InvokeRepeating("UpdatePath", 0f, .5f);
     animator = GetComponent <Animator>();
 }
示例#8
0
    void OnTriggerEnter2D(Collider2D col)
    {
        if (chef.attack && col.gameObject.tag == "Enemy")
        {
            enemy         = col.gameObject.GetComponent <enemyInfo>();
            enemy.health -= chef.weaponDamage[chef.weaponChoice] * enemy.weaponDamage[chef.weaponChoice];

            if (col.gameObject.transform.position.x < this.transform.position.x)
            {
                col.gameObject.rigidbody2D.velocity = new Vector2(-horKnockback, verKnockback);
            }
            else
            {
                col.gameObject.rigidbody2D.velocity = new Vector2(horKnockback, verKnockback);
            }
        }
    }
示例#9
0
 //角色受到碰撞时触发回调函数
 private void OnCollisionEnter2D(Collision2D collision)
 {
     //如果碰撞体为敌人则表现受击硬直
     if (collision.gameObject.tag == "enemy" && Time.time - status.LastAttackedTime > status.stiffTime)
     {
         status.IsAttacked = true;
         enemyInfo einfo = collision.gameObject.GetComponent <enemyInfo>();
         status.UpdateBlood(-status.calculateDamage(einfo.thisInfo.AttackPower));
         status.LastAttackedTime = Time.time;
         SpriteRenderer sprite = GetComponent <SpriteRenderer>();
         sprite.color         = Color.red;
         rigidbody2d.velocity = collision.GetContact(0).normal *status.moveSpeed;
         if (!audio.isPlaying)
         {
             audio.PlayOneShot(attacked);
         }
     }
 }
示例#10
0
 public void Instance_OnCreateEnemy(enemyInfo enemydata)
 {
     EnemyCreateManager(enemydata.num, enemydata.enemyClass, enemydata.pos);
 }
示例#11
0
 public levelInfo(enemyInfo newEnemyInfo)
 {
     thisLevelEnemyInfo = newEnemyInfo;
 }
示例#12
0
    public void HandleMessage(string message)
    {
        Debug.Log("HandleMessage:" + message);
        int    target  = message.IndexOf(":");
        string tag     = message.Substring(0, target);
        string content = message.Substring(target + 1);

        switch (tag)
        {
        case "register":
            if (OnRegisterResult != null)
            {
                OnRegisterResult(content);
            }
            break;

        case "login":

            if (OnLoginResult != null)
            {
                OnLoginResult(content);
            }

            break;

        case "createPlayer":

            RedayInfo redayinfo = GetData2 <RedayInfo>(content);

            if (OnCreatePlayer != null)
            {
                Debug.Log(content);
                OnCreatePlayer(redayinfo);
            }

            break;

        case "playerstatus":
            PlayerInfo player = GetData2 <PlayerInfo>(content);
            if (OnUpdataPlayer != null)
            {
                OnUpdataPlayer(player);
            }

            break;

        case "reday":
            if (content == "go!" && OnStartResult != null)
            {
                OnStartResult(content);
            }
            break;

        case "Tankstatus":
            Debug.Log(content);
            TankInfo tankinfo = GetData2 <TankInfo>(content);
            if (OnUpdateTank != null)
            {
                OnUpdateTank(tankinfo);
            }
            break;

        case "createEnemy":
            Debug.Log("收到创建");
            enemyInfo enemyInfo = GetData2 <enemyInfo>(content);
            if (OnCreateEnemy != null)
            {
                OnCreateEnemy(enemyInfo);
            }
            break;

        case "GamePass":
            if (content == "first")
            {
                if (OnGameCount != null)
                {
                    OnGameCount(content);
                }
                NetWorkManage.Instance.SendMessage("CreateEnemy:{\"enemy\":2}");
            }
            else if (content == "second")
            {
                if (OnGameCount != null)
                {
                    OnGameCount(content);
                }
                NetWorkManage.Instance.SendMessage("CreateEnemy:{\"enemy\":3}");
            }
            else
            {
                SceneManager.LoadScene("Scenes/win");
            }
            break;

        case "EnemyDie":
            EnemyDie enemydie = GetData2 <EnemyDie>(content);
            if (OnEnemyDie != null)
            {
                OnEnemyDie(enemydie);
            }
            break;

        case "EnemyBoom":
            EnemyDie enemyboom = GetData2 <EnemyDie>(content);
            if (OnEnemyBoom != null)
            {
                OnEnemyBoom(enemyboom);
            }
            break;

        case "PlayerUpdata":
            PlayerUpdata playerupdata = GetData2 <PlayerUpdata>(content);
            if (OnPlayerUpdata != null)
            {
                OnPlayerUpdata(playerupdata);
            }
            break;

        case "Enemytarget":
            NavMeshInfo navMeshInfo = GetData2 <NavMeshInfo>(content);
            if (OnWayPoint != null)
            {
                OnWayPoint(navMeshInfo);
            }
            break;

        case "MoneyUpdata":
            MoneyUpdata money = GetData2 <MoneyUpdata>(content);
            if (OnMoneyUpdata != null)
            {
                OnMoneyUpdata(money);
            }
            break;

        case "GameOver":
            SceneManager.LoadScene("Scenes/GameOver");
            break;

        default:
            break;
        }
    }