using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class disparo : MonoBehaviour {
public Transform player;
// public float range = 1f;
//public float range = 4f;
// MANIPULAR PARA CAMBIAR LAS VELOCIDADES DE DISPARO
public float range = 0.04f;
public float bulletImpulse = 0.1f;
private bool onRange = false;
public Rigidbody projectile;
void Start()
{
// float rand = Random.Range(1.0f, 2.0f);/////ORIGINAL
//float rand = Random.Range(0.04f, 2.0f);/////tambien funciona
//float rand = Random.Range(0.04f, 0.5f);/////tambien funciona
//ATENCION A ESTAS LINEAS DE ARRIBA, MANIPULANDOLAS SE CAMBIAS LOS TIEMPOS
DE DISPAROS A MAS LENTOS A MAS RAPIDOS Y SEGUIDOS
// float rand = Random.Range(1.0f, 2.0f);/////ORIGINAL DISPARA LENTAMENTE
float rand = Random.Range(0.04f, 0.08f);
/////tambien funcionaDISPARA RAPIDAMENTE
InvokeRepeating("Shoot", 2, rand);//////ORIGINAL
}
void Shoot()
{
if (onRange)
{
Rigidbody bullet = (Rigidbody)Instantiate(projectile, transform.position + transform.forward, transform.rotation);
bullet.AddForce(transform.forward * bulletImpulse, ForceMode.Impulse);
Destroy(bullet.gameObject, 2);
}
}
void Update()
{
onRange = Vector3.Distance(transform.position, player.position) < range;
if (onRange)
transform.LookAt(player);
}
}
---------------------------------------------------------------------------
---------------------------------------------------------------------------
-------------------------------------------------------------------------
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class disparo : MonoBehaviour {
public Transform player;
// public float range = 1f;
//public float range = 4f;
public float range = 0.04f;
public float bulletImpulse = 0.1f;
private bool onRange = false;
public Rigidbody projectile;
void Start()
{
// float rand = Random.Range(1.0f, 2.0f);/////ORIGINAL
//float rand = Random.Range(0.04f, 2.0f);/////tambien funciona
//float rand = Random.Range(0.04f, 0.5f);/////tambien funciona
float rand = Random.Range(0.04f, 0.08f);/////tambien funciona
InvokeRepeating("Shoot", 2, rand);//////ORIGINAL
}
void Shoot()
{
if (onRange)
{
Rigidbody bullet = (Rigidbody)Instantiate(projectile, transform.position + transform.forward, transform.rotation);
bullet.AddForce(transform.forward * bulletImpulse, ForceMode.Impulse);
Destroy(bullet.gameObject, 2);
}
}
void Update()
{
onRange = Vector3.Distance(transform.position, player.position) < range;
if (onRange)
transform.LookAt(player);
}
}
No hay comentarios:
Publicar un comentario