etol4040
Hectopat
- Katılım
- 10 Mayıs 2020
- Mesajlar
- 937
- Çözümler
- 7
Şu an bir FPS oyun yapıyorum ama silhın ucundan ateş edince çıkan şeyi ateş edince nasıl açıp kapatıyoruz?
Biliyorum yapmayı da yeni bir ders yok muzzleflash eklemekle ilgili particle sistemi değişti onun için de eskileri olmuyor.
Eğer biliyorsanız söyleyin burada takıldım :\
Biliyorsanız birde;
Başka bir scripte geçtim
using System.Collections;
using UnityEngine;
using System.Collections.Generic;
public class MuzzleFlash : MonoBehaviour {
{
public GameObject theGun;
public AudioSource gunShot;
public bool isFiring = false;
public GameObject muzzleFlash;
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
if (isFiring == false)
{
StartCoroutine(FireHandgun());
}
}
}
IEnumerator FireHandgun()
{
isFiring = true;
theGun.GetComponent<Animator>().Play("PistolFire");
muzzleFlash.SetActive(true);
gunShot.Play();
yield return new WaitForSeconds(0.05f)
muzzleFlash.SetActive(false);
yield return new WaitForSeconds(0.45f);
theGun.GetComponent<Animator>().Play("New State");
isFiring = false;
}
}
Biliyorum yapmayı da yeni bir ders yok muzzleflash eklemekle ilgili particle sistemi değişti onun için de eskileri olmuyor.
C#:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class atesetme : MonoBehaviour {
public float mermı, sarjor, taplammermi, menzil, hasar1, hasar2, sıradakiates, ateszamani, sayi, zaman, maxzaman;
public bool ates,reload;
RaycastHit hit;
public Text mermiyazi;
void Start () {
zaman = maxzaman;
}
// Update is called once per frame
void Update () {
mermiyazi.text = ""+mermı+"/"+taplammermi;
if (Input.GetMouseButton(0) && mermı > 0 && Time.time > sıradakiates && !reload){
ates = true;
sıradakiates = Time.time + ateszamani;
mermı -= 1;
}
if (Input.GetKeyDown(KeyCode.R) && mermı != 30 && !reload)
{
reload = true;
}
if (reload)
{
sayi = sarjor - mermı;
zaman -= Time.deltaTime;
if(zaman <= 0)
{
reload = false;
zaman = maxzaman;
if (sayi > taplammermi)
{
mermı += taplammermi;
taplammermi = 0;
}
if (sayi < taplammermi)
{
mermı += sayi;
taplammermi -= sayi;
}
}
}
}
void FixedUpdate()
{
if (ates) {
ates = false;
if (Physics.Raycast(Camera.main.transform.position,Camera.main.transform.forward,out hit,menzil)){
if(hit.transform.tag == "Düşman")
{
Debug.Log("düşmana değdin");
}
}
}
}
}
Kod Böyleydi fakat böyle yapınca Compiler Error veriyor yeni yöntemi nedir?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class AtesEtme : MonoBehaviour
{
public float mermı, sarjor, taplammermi, menzil, hasar1, hasar2, sıradakiates, ateszamani, sayi, zaman, maxzaman;
public bool ates, reload;
RaycastHit hit;
public Text mermiyazi;
ParticleEmitter muzzle;
void Start()
{
zaman = maxzaman;
}
// Update is called once per frame
void Update()
{
mermiyazi.text = "" + mermı + "/" + taplammermi;
if (Input.GetMouseButton(0) && mermı > 0 && Time.time > sıradakiates && !reload)
{
ates = true;
muzzle.emit = true
sıradakiates = Time.time + ateszamani;
mermı -= 1;
if (Input.GetMouseButtonUp(0) || mermiyazi == 0) {
{
muzzle.emit = false
}
if (Input.GetKeyDown(KeyCode.R) && mermı != 30 && !reload)
{
reload = true;
}
if (reload)
{
sayi = sarjor - mermı;
zaman -= Time.deltaTime;
if (zaman <= 0)
{
reload = false;
zaman = maxzaman;
if (sayi > taplammermi)
{
mermı += taplammermi;
taplammermi = 0;
}
if (sayi < taplammermi)
{
mermı += sayi;
taplammermi -= sayi;
}
}
}
}
void FixedUpdate()
{
if (ates)
{
ates = false;
if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, menzil))
{
if (hit.transform.tag == "Düşman")
{
Debug.Log("düşmana değdin");
}
}
}
}
}
Eğer biliyorsanız söyleyin burada takıldım :\
Biliyorsanız birde;
C#:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class AtesEtme : MonoBehaviour
{
public GameObject theGun;
public AudioSource gunShot;
public GameObject muzzleFlash
public float mermı, sarjor, taplammermi, menzil, hasar1, hasar2, sıradakiates, ateszamani, sayi, zaman, maxzaman;(unexpected symbol "public"in class scruct or interface member definication)
public bool ates, reload;
RaycastHit hit;
public Text mermiyazi;
void Start()
{
zaman = maxzaman;
}
// Update is called once per frame
void Update()
{
mermiyazi.text = "" + mermı + "/" + taplammermi;
if (Input.GetMouseButton(0) && mermı > 0 && Time.time > sıradakiates && !reload)
{
ates = true;
sıradakiates = Time.time + ateszamani;
mermı -= 1;
}
if (Input.GetKeyDown(KeyCode.R) && mermı != 30 && !reload)
{
reload = true;
}
if (reload)
{
sayi = sarjor - mermı;
zaman -= Time.deltaTime;
if (zaman <= 0)
{
reload = false;
zaman = maxzaman;
if (sayi > taplammermi)
{
mermı += taplammermi;
taplammermi = 0;
}
if (sayi < taplammermi)
{
mermı += sayi;
taplammermi -= sayi;
}
}
}
}
void FixedUpdate()
{
if (ates)
{
ates = false;
if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, menzil))
{
if (hit.transform.tag == "Düşman")
{
Debug.Log("düşmana değdin");
}
}
}
}
}
using System.Collections;
using UnityEngine;
using System.Collections.Generic;
public class MuzzleFlash : MonoBehaviour {
{
public GameObject theGun;
public AudioSource gunShot;
public bool isFiring = false;
public GameObject muzzleFlash;
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
if (isFiring == false)
{
StartCoroutine(FireHandgun());
}
}
}
IEnumerator FireHandgun()
{
isFiring = true;
theGun.GetComponent<Animator>().Play("PistolFire");
muzzleFlash.SetActive(true);
gunShot.Play();
yield return new WaitForSeconds(0.05f)
muzzleFlash.SetActive(false);
yield return new WaitForSeconds(0.45f);
theGun.GetComponent<Animator>().Play("New State");
isFiring = false;
}
}
[/CODE]C#:[CODE=csharp]using System.Collections; using UnityEngine; using System.Collections.Generic; public class MuzzleFlash : MonoBehaviour { { public GameObject theGun; public AudioSource gunShot; public bool isFiring = false; public GameObject muzzleFlash; void Update() { if (Input.GetButtonDown("Fire1")) { if (isFiring == false) { StartCoroutine(FireHandgun()); } } } IEnumerator FireHandgun() { isFiring = true; theGun.GetComponent<Animator>().Play("PistolFire"); muzzleFlash.SetActive(true); gunShot.Play(); yield return new WaitForSeconds(0.05f) muzzleFlash.SetActive(false); yield return new WaitForSeconds(0.45f); theGun.GetComponent<Animator>().Play("New State"); isFiring = false; } }
Son düzenleme: