PlayerController.cs 1.19 KB
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent (typeof (Rigidbody))]
public class PlayerController : MonoBehaviour {

    Rigidbody myRigidbody;
    Vector3 velocity;
    public GameObject target;
    public Grenade grenade;
    public Transform grenadeSpawner;

    public float m_TimeBetThrow = 2.0f;

    private float m_LastThrowTime;

	// Use this for initialization
	void Start () {
        myRigidbody = GetComponent<Rigidbody>();
    }
	
	public void Move(Vector3 _velocity)
    {
        velocity = _velocity;
    }

    private void FixedUpdate()
    {
        myRigidbody.MovePosition(myRigidbody.position + velocity * Time.deltaTime);
        
    }

    private void Update()
    {
        if (GravityBall.Instance.GetButton() && Time.time >= m_LastThrowTime + m_TimeBetThrow)
        {
            m_LastThrowTime = Time.time;
            Shoot();
            //Debug.Log("throwGrenade");
            //Instantiate(grenadePrefab, grenadeSpawner);
        }
    }

    public void Shoot()
    {
        Grenade newGrenade = Instantiate(grenade, grenadeSpawner.position, grenadeSpawner.rotation) as Grenade;
        //newGrenade.setSpeed(10);
    }
}