Jump to content
View in the app

A better way to browse. Learn more.

GTAGames.nl - De Nederlandse Grand Theft Auto Community!

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Hallo,

Ik ben bezig met een game en heb al een schiet-script die een kogel afvuurt, een bullethole texture neerzet, maar nog geen animaties en ammo etc.

Mijn vraag is of jullie me daarbij kunnen helpen :)

Ik heb dit script van internet (de beste die bij mij werkte :puh:)

!!EDIT!! in de code staat "public float delayTime = 0.5 f"

in unity staat bij mij 0.1

using UnityEngine;
using System.Collections;
public class Shoot : MonoBehaviour {
public GameObject bullet;
public GameObject bulletHole;
public float delayTime = 0.5f;

private float counter = 0;

void FixedUpdate ()
{
if(Input.GetKey(KeyCode.Mouse0) && counter > delayTime)
{
Instantiate(bullet, transform.position, transform.rotation);
audio.Play();
counter = 0;

RaycastHit hit;
Ray ray = new Ray(transform.position, transform.forward);
if(Physics.Raycast(ray, out hit, 100f))
{
Instantiate(bulletHole, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal));
}
}
counter += Time.deltaTime;
}
}

Het probleem is dat hij een animatie moet afspelen als hij schiet(recoil ofzoiets)

Als de ammo op is, een animatie dat hij herlaad, en als je op R drukt dat hij ook een laad animatie afspeelt, en dat je ook op het scherm kan zien hoeveel ammo je nog hebt

Ik vraag jullie, omdat ik zelf geen code kan (wat niet is kan altijd nog komen :puh:), maar in mijn hoofd ziet het er zo uit:

Ammo 30:30 (30 in je clip en 30 op zak)

Bam bam bam :puh: (per keer dat er geschoten is, speel recoil animatie af)

Ammo min het aantal keren geschoten

Als de ammo 0 is (0 in je clip 30 op zak), speel animatie af van het herladen...

Ammo 30 (30 in je clip 0 op zak)

en misschien mogelijk ook dat je ammo kan oprapen, ook in mn hoofd:

Ammo 30 (30 in je clip 0 op zak)

bam bam (per keer dat er geschoten is, speel recoil animatie af)

ammo 0 (0 in je clip 0 op zak)

Als je door een trigger loopt met een tag Ammo, ammo is weer 30 (30 op zak en 0 in je clip)

Dan herlaad je (animatie afspelen) ammo is dan 0 op zak en 30 in je clip,

Dit ziet er waarschijnlijk erg warrig uit, maar ik probeer het zo goed mogelijk uit te leggen :puh:

Mijn vraag aan de programmeurs hier is of ze dat misschien in het script kunnen verwerken :)

mvg

llllllllll

Edited by llllllllll

Featured Replies

Als ok thuis ben zal ik ff kijken. :puh: Heb je zelf animatie's of moet ik die zelf maken?

Edited by Ezra24rct3

  • Author

Als ok thuis ben zal ik ff kijken. :puh: Heb je zelf animatie's of moet ik die zelf maken?

De animaties heb ik zelf :-)

Oké. Mag ik de namen van de animaties en een beschrijving van waar je hem voor wilt gebruiken?

  • Author

Oké. Mag ik de namen van de animaties en een beschrijving van waar je hem voor wilt gebruiken?

Jazeker:

Reloading voor het herladen

Shooting voor de recoil/schieten

mvg llllllllll

  • Author

UPDATE:

Ik heb nu dus een script voor een muzzle flash, maar hoe implementeer ik dat script in mn schiet script

Het schietscript in C#:

using UnityEngine;
using System.Collections;
public class Shoot : MonoBehaviour {
public GameObject bullet;
public GameObject bulletHole;
public float delayTime = 0.5f;

private float counter = 0;

void FixedUpdate ()
 {
 if(Input.GetKey(KeyCode.Mouse0) && counter > delayTime)
 {
  Instantiate(bullet, transform.position, transform.rotation);
  audio.Play();
  counter = 0;

  RaycastHit hit;
  Ray ray = new Ray(transform.position, transform.forward);
  if(Physics.Raycast(ray, out hit, 100f))
  {
   Instantiate(bulletHole, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal));
  }
 }
 counter += Time.deltaTime;
}
}

En het muzzleflash script in Javascript (of Unityscript):

#pragma strict
var muzzleFlash : Renderer;
var muzzleLight : Light;
function Start ()
{
muzzleFlash.enabled = false;
muzzleLight.enabled = false;
}
function Update()
{
if (Input.GetButtonDown("Fire1"))
{
Shoot();
}
}
function Shoot()
{
muzzleFlash.renderer.enabled = true;
muzzleLight.enabled = true;
yield WaitForSeconds (0.1);
muzzleFlash.renderer.enabled = false;
muzzleLight.enabled = false;
Start();
}

Ik heb zelf geen idee, dus jullie hulp is zeer dankbaar :-)

mvg llllllllll

Je zal het moeten vertalen naar C#. Hoe dat moet weet ik niet, heb zelf niet veel Java ervaring, al ben ik er wel mee begonnen.

  • Author

Je zal het moeten vertalen naar C#. Hoe dat moet weet ik niet, heb zelf niet veel Java ervaring, al ben ik er wel mee begonnen.

Okey, ik zal ff kijken op internet ;-)

mvg llllllllll

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Recently Browsing 0

  • No registered users viewing this page.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.