11월 02일 (목)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestCannonBall : MonoBehaviour
{
[SerializeField] private float cannonSpeed = 3f;
[SerializeField] private Rigidbody rb;
private void Start()
{
this.rb.AddRelativeForce(transform.forward * cannonSpeed, ForceMode.Impulse);
}
private void FixedUpdate()
{
//this.FireCannonBall();
this.DestroyCannonBall();
}
private void FireCannonBall()
{
//this.transform.Translate(Vector3.forward * this.cannonSpeed * Time.deltaTime);
}
private void DestroyCannonBall()
{
if(this.transform.position.y <= 0)
{
Destroy(this.gameObject);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestCannon : MonoBehaviour
{
[SerializeField] private GameObject cannonBallGo;
[SerializeField] private Transform cannonTr;
private float elapsedTime = 0f;
// Update is called once per frame
void Update()
{
OVRPlugin.systemDisplayFrequency = 90.0f;
this.CannonAttack();
}
private void CannonAttack()
{
//3초 간격
this.elapsedTime += Time.deltaTime;
if(this.elapsedTime >= 2f)
{
//대포 발사
GameObject cannonBall = Instantiate(this.cannonBallGo);
cannonBall.transform.position = this.cannonTr.position;
cannonBall.transform.rotation = this.cannonTr.rotation;
this.elapsedTime = 0f;
}
}
}