﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class AddForceToPrefab : MonoBehaviour
{

    
    // Put this on the GameObject to launch - add a ridigbody
    // Start it from an event trigger by calling LaunchPrefab()
    // Change thrust as needed in the inspector
    // If using parent to ARcamera, you can optionaly unparent it upon launch.


    /*************************************************************************
* 
* ARConnex
* __________________
* 
*  [2017] - [2020] ARConnex Incorporated 
*  All Rights Reserved.
* 
* NOTICE:  All information contained herein is, and remains
* the property of ARConnex Incorporated and its suppliers,
* if any.  The intellectual and technical concepts contained
* herein are proprietary to ARConnex Incorporated
* and its suppliers and may be covered by U.S. and Foreign Patents,
* patents in process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from ARConnex Incorporated or if used for display in the ARConnex Reality Browser.
*/




    public float thrust;
    Rigidbody rb;
    private bool launch;
    public bool unparentOnlaunch;

    void FixedUpdate()
    {
        if (launch)
        {
            if(GetComponent<Rigidbody>() != null)
            {
                rb = GetComponent<Rigidbody>();
                if (SceneManager.GetActiveScene().name == "GPScenenew")
                {
                    rb.AddRelativeForce(new Vector3(0,0,1) * thrust);
                }
                else
                {
                    rb.AddRelativeForce(new Vector3(0,0,1) * thrust);
                }
                

                if (unparentOnlaunch)
                {
                   transform.SetParent(null);
                }                
            }
            launch = false;
        }
    }

       public void LaunchPrefab()
        {
            launch = true;
        }   

}