Exemple #1
0
    void Awake()
    {
        current_horizontal_speed = horizontal_speed;

        lauchPhase = LauchPhase.HORIZONTAL;

        body            = gameObject.GetComponent <Rigidbody>();
        body.useGravity = false;

        if (force == null)
        {
            force = GameObject.Find("Arrow");
        }
        if (power_bar == null)
        {
            power_bar = GameObject.Find("Power").GetComponent <Scrollbar>();
        }

        camera = GameObject.Find("ARCamera");

        audioSource = GameObject.Find("SFX").GetComponent <AudioSource>();
        SetPowerColors();
        Debug.Log("Arrow starts with this Y angle:" + start_Y_angle);

        ten_points = false;
    }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        if (lauchPhase == LauchPhase.HORIZONTAL)
        {
            if (GetMousePress())
            {
                lauchPhase = LauchPhase.POWER;
            }
        }
        else if (lauchPhase == LauchPhase.POWER)
        {
            LaunchBallLogic();
        }

        if (lauchPhase != LauchPhase.LAUNCHED)
        {
            SetWithCamera();
        }
    }
Exemple #3
0
    public void LaunchBallLogic()
    {
        current_prevention_time += Time.deltaTime;
        Debug.Log("Prevention time is " + current_prevention_time);

        // to not confuse the last arrow click
        if (current_prevention_time <= prevention_time)
        {
            return;
        }

        // Change colors
        SetPowerColors();

        // only launch ball when releasing
        if ((Input.GetKeyUp(KeyCode.Mouse0) == false))
        {
            return;
        }

        Debug.Log("Ball about to be launched!");

        // Body
        body.useGravity = true;

        // Launch in camera direction but with an upwards angle
        Vector3 direction   = (camera.transform.forward + new Vector3(0, 1f, 0)).normalized;
        Vector3 forceVector = direction * forceStrength * power_bar.value;

        body.AddForce(forceVector, ForceMode.Impulse);

        // Audio
        audioSource.clip   = Resources.Load("Sound/throw") as AudioClip;
        audioSource.volume = power_bar.value;
        audioSource.Play();

        // Phase
        lauchPhase = LauchPhase.LAUNCHED;
    }