PlayerController.cs
1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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);
}
}