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

namespace Arugula.Prototypical
{
    public class InitialVelocity : MonoBehaviour
    {
        public Space space;
        public Vector3 velocity;
        // Start is called before the first frame update
        private void Start()
        {
            if (GetComponent<Rigidbody>())
            {
                GetComponent<Rigidbody>().velocity = Velocity3D;
            }
            else if (GetComponent<Rigidbody2D>())
            {
                GetComponent<Rigidbody2D>().velocity = Velocity2D;
            }
        }

        public Vector3 Velocity3D
        {
            get
            {
                return space == Space.World ? velocity : transform.rotation * velocity;
            }
        }

        public Vector3 Velocity2D
        {
            get
            {
                return space == Space.World ? velocity : transform.rotation * velocity;
            }
        }
    }

}
