示例#1
0
 /**********************************************************************************/
 // переключаем нашу пулю в состояние "взрыва"
 //
 /**********************************************************************************/
 protected void BurnBullet()
 {
     CameraControllerDuelMode.ShakeCamera(ShakePower);   // сотрясаем камеру, если нужно
     m_state = BULLET_STATE.BURN;
     m_animator.SetBool("Burn", true);
     PlayBurstSoundEffect();
 }
示例#2
0
    /**********************************************************************************/
    // функция сброски параметров к дефолтным
    //
    /**********************************************************************************/
    override public void ResetGObject()
    {
        m_state = BULLET_STATE.FLY;
        gameObject.SetActive(true);
        speed = m_originalSpeed;
        m_collider.enabled = true;

        PlayShotSoundEffect();
    }
示例#3
0
    void SetStateToReturning()
    {
        state = BULLET_STATE.RETURNING;

        RotationTime = Vector3.zero;

        currentTiming = 0.0f;

        RotationTime.x = gameScript.GetRandomFloat( MIN_ROTATION_TIME, MAX_ROTATION_TIME );
        RotationTime.y = gameScript.GetRandomFloat( MIN_ROTATION_TIME, MAX_ROTATION_TIME );
        RotationTime.z = gameScript.GetRandomFloat( MIN_ROTATION_TIME, MAX_ROTATION_TIME );

        originalDirection = direction;
    }
示例#4
0
    void Update()
    {
        if( block_reverse_time < MAX_BLOCK_TIME )
        {
            block_reverse_time += Time.deltaTime;
        }

        float
            distance,
            speed;

        if( direction == Vector3.zero )
        {
            direction = transform.forward;
            distance = 0.0f;
        }
        else if( flipped != Vector3.one )
        {
            ++flipCounter;
        }

        targetDirection = player.position - transform.position;
        distance = targetDirection.magnitude;
        targetDirection.Normalize();

        if( transform.localScale.x < 4.0f )
        {
            transform.localScale *= 1.0f + 5.0f * Time.deltaTime;
        }
        else
        {
            PhysicsBullet.active = true;
        }

        speed = SPEED;

        if( distance < MIN_DISTANCE )
        {
            speed *= Mathf.Clamp( distance / MIN_DISTANCE, 0.35f, 1.0f );
        }

        if( state == BULLET_STATE.GOING )
        {
            if( distance > MAX_DISTANCE )
            {
                SetStateToReturning();
            }

            rigidBody.velocity = GetVelocity( speed );
        }
        else // returning
        {
            currentTiming += Time.deltaTime;

            direction.x = Mathf.Lerp( originalDirection.x, targetDirection.x, currentTiming / RotationTime.x );
            direction.y = Mathf.Lerp( originalDirection.y, targetDirection.y, currentTiming / RotationTime.y );
            direction.z = Mathf.Lerp( originalDirection.z, targetDirection.z, currentTiming / RotationTime.z );

            rigidBody.velocity = GetVelocity( speed );

            if( distance < MIN_DISTANCE )
            {
                state = BULLET_STATE.GOING;
            }
        }

        /*if( PhysicsBullet.transform.position.y < 1.0f && direction.y < 0.0f )
        {
            direction.y *= -1.0f;
        }
        else if( PhysicsBullet.transform.position.y < -1.0f )
        {
            Destroy( gameObject );
        }*/

        transform.LookAt( transform.position + direction );

        if( flipCounter > 25 && flipped != Vector3.one )
        {
            flipped = Vector3.one;
            flipCounter = 0;

            direction = PhysicsBullet.transform.position - oldPosition;
            direction.Normalize();

            SetStateToReturning();
        }

        oldPosition = PhysicsBullet.transform.position;
    }
示例#5
0
    void Start()
    {
        player = GameObject.FindWithTag( TAGS.PLAYER ).transform;
        gameScript = GameObject.FindWithTag( TAGS.WORLD ).GetComponent< GameScript >();

        rigidBody = GetComponent< Rigidbody >();
        state = BULLET_STATE.GOING;

        direction = Vector3.zero;

        type = ( BULLET_TYPE ) BULLET_COUNTER;
        groupID = GROUP_COUNTER;

        YFlipBlocked = false;

        flipped = Vector3.one;

        IsDead = false;

        if( ++BULLET_COUNTER >= ( int ) BULLET_TYPE.COUNT )
        {
            BULLET_COUNTER = 0;
            ++GROUP_COUNTER;
        }

        block_reverse_time = MAX_BLOCK_TIME;

        switch( type )
        {
            case BULLET_TYPE.RED:
            {
                trail.material =
                    ( Material ) Instantiate( Resources.Load( "BULLET_TRAIL_RED_MATERIAL" ) );
            } break;

            case BULLET_TYPE.PURPLE:
            {
                trail.material =
                    ( Material ) Instantiate( Resources.Load( "BULLET_TRAIL_PURPLE_MATERIAL" ) );
            } break;

            case BULLET_TYPE.YELLOW:
            {
                trail.material =
                    ( Material ) Instantiate( Resources.Load( "BULLET_TRAIL_YELLOW_MATERIAL" ) );
            } break;
        }
    }
示例#6
0
    public void OnFadeBegin()
    {
        this.GetComponent<Collider>().enabled = false;
        this.state = BulletBase.BULLET_STATE.FADING;
        this.GetComponent<Rigidbody>().velocity = Vector3.zero;
        foreach ( ParticleEmitter emitter in this.GetComponentsInChildren<ParticleEmitter>() )
        {
            emitter.emit = false;
        }

        // The trail renderer is shrunk in Update()
    }
示例#7
0
    /// <summary>
    /// Called every frame
    /// </summary>
    protected virtual void Update()
    {
        if ( this.state == BULLET_STATE.FADING )
        {
            this.fadeTime += Time.deltaTime;

            TrailRenderer trail = this.GetComponent<TrailRenderer>();
            if ( trail != null )
            {
                this.GetComponent<TrailRenderer>().time = (1.0f - this.fadeTime / this.desc.fadeOut )
                    * this.desc.prefab.GetComponent<TrailRenderer>().time;
            }

            if ( this.fadeTime >= this.desc.fadeOut )
            {
                // If it is a missile, it will have to be destroyed
                if ( this.desc.smartBullet )
                {
                    if ( Network.peerType == NetworkPeerType.Disconnected )
                    {
                        GameObject.Destroy( this.gameObject );
                    }
                    else if ( this.GetComponent<NetworkView>().isMine )
                    {
                        Network.Destroy( this.gameObject );
                    }
                }
                else // If not, then disable it
                {
                    this.state = BULLET_STATE.INACTIVE;
                    this.gameObject.SetActive( false );
                }
            }
        }
        else if ( this.state == BULLET_STATE.ACTIVE_OWNED )
        {
            this.distanceTravelled += this.desc.moveSpeed * Time.deltaTime;
            if ( this.distanceTravelled >= this.desc.maxDistance )
            {
                this.OnLifetimeExpiration();
            }

            //Advanced collision checking - note that it calls OnTriggerEnter by hand.
            switch( desc.collisionType )
            {
            case COLLISION_TYPE.COLLISION_SPHERE:
                this.DetectSphereCollision();
                break;
            case COLLISION_TYPE.COLLISION_DEFAULT:
                break;
            case COLLISION_TYPE.COLLISION_RAY:
                this.DetectRaycastCollision();
                break;
            default:
                break;

            }

            this.lastPosition = this.transform.position;
        }
    }