UnityProjekt/Assets/Scripts/WeaponFireController.cs

34 lines
895 B
C#
Raw Normal View History

2020-11-06 20:20:17 +00:00
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class WeaponFireController : MonoBehaviour
{
public GameObject prefab;
2020-11-06 20:20:17 +00:00
public Transform firePoint;
private ObjectPool _pool;
2020-11-06 20:20:17 +00:00
// Start is called before the first frame update
void Start()
{
_pool = new ObjectPool(prefab, 10);
2020-11-06 20:20:17 +00:00
}
// Update is called once per frame
void Update()
{
if(Input.GetButtonDown("Fire1"))
{
var theRocket = _pool.GetObject();
2020-11-06 20:20:17 +00:00
var rocketTransform = theRocket.transform;
rocketTransform.position = firePoint.position;
var scale = rocketTransform.localScale;
if (transform.localScale.x * scale.x < 0)
scale.x *= -1;
rocketTransform.localScale = scale;
theRocket.SetActive(true);
2020-11-06 20:20:17 +00:00
}
}
}