コード例 #1
0
    /// <summary>
    /// Use this for initialization
    /// </summary>
    void Start()
    {
        // apply impulse force to get projectile moving
        GetComponent <Rigidbody2D>().AddForce(
            new Vector2(0, -ConfigurationUtils.TeddyBearProjectileImpulseForce),
            ForceMode2D.Impulse);

        // initialize homing component
        HomingComponent homingComponent = GetComponent <HomingComponent>();

        homingComponent.SetImpulseForce(ConfigurationUtils.TeddyBearProjectileImpulseForce);
    }
コード例 #2
0
    /// <summary>
    /// Use this for initialization
    /// </summary>
    void Start()
    {
        // apply impulse force to get teddy bear moving
        float   angle     = Random.Range(0, 2 * Mathf.PI);
        Vector2 direction = new Vector2(
            Mathf.Cos(angle), Mathf.Sin(angle));
        float magnitude = Random.Range(ConfigurationUtils.MinImpulseForce,
                                       ConfigurationUtils.MaxImpulseForce);
        Vector2 force = direction * magnitude;

        GetComponent <Rigidbody2D>().AddForce(force,
                                              ForceMode2D.Impulse);

        // initialize homing component
        HomingComponent homingComponent = GetComponent <HomingComponent>();

        homingComponent.SetImpulseForce(force.magnitude);

        // create and start timer
        shootTimer = gameObject.AddComponent <Timer>();
        shootTimer.AddTimerFinishedEventListener(HandleTimerFinishedEvent);
        StartRandomTimer();
    }