// Update is called once per frame
    void Update()
    {
        if (_rno == RNO.MOVE)
        {
            Vector3 vec = mDestLocalPos - transform.localPosition;
            float   spd = 0.08f * Time.deltaTime;
            if (vec.magnitude < spd)
            {
                _rno = RNO.IDLE;
                transform.localPosition = mDestLocalPos;
            }
            Vector3 dirVec = vec.normalized * spd;
            transform.localPosition += dirVec;
            transform.rotation       = TmMath.LookRotation2D(dirVec, Vector2.up);
            return;
        }
        if (mBulletTimer > 0)
        {
            mBulletTimer -= Time.deltaTime;
        }
        float      distSqMin = distMinSq;
        GameObject em        = null;

        GameObject[] ems = mGame.emList;
        foreach (GameObject go in ems)
        {
            float distSqc = (go.transform.position - transform.position).sqrMagnitude;
            if (distSqc < distSqMin)
            {
                distSqMin = distSqc;
                em        = go;
            }
        }
        if (em != null)
        {
            Vector3 sizeVec = em.transform.position - transform.position;
            if (sizeVec.sqrMagnitude < distMinSq)
            {
                Vector3 emWorldSpd = em.GetComponent <enemyBase>().worldSpeed;
                sizeVec            = getClossPoint(em.transform.position, emWorldSpd, transform.position, bulletSpeed) - transform.position;
                transform.rotation = TmMath.LookRotation2D(sizeVec, Vector2.up);
            }
            if (mBulletTimer <= 0.0f)
            {
                mBulletTimer += Random.Range(bulletInterval * 0.9f, bulletInterval * 1.1f);
                GameObject bl = GameObject.Instantiate(bulletPrefab, transform.position, transform.rotation) as GameObject;
                bl.tag = "tagBullet";
                bl.transform.parent = transform.parent;
                bulletParam param = new bulletParam(bulletSpeed, 1.0f, bulleteLifeTime);
                bl.SendMessage("SM_SetBulletSpeed", param);
            }
        }
    }
Beispiel #2
0
 //------------------------------------------------------
 public void SM_SetBulletSpeed(bulletParam _param)
 {
     mBulletSpeed = _param.speed;
     mDeleteTimer = _param.deleteTime;
 }