Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.


  • Content count

  • Joined

  • Last visited

Community Reputation

5 Neutral

About CakeMonsTv

  • Rank

Contact Methods

Profile Information

  • Gender
  • Location:
  • Interests
    game developer

Recent Profile Visitors

480 profile views
  1. Reload script bug

  2. Reload script bug

    Thanks! I managed to make it good looking and working with this help of yours.
  3. Reload script bug

    Edited the post with additional information (bottom of the post)
  4. Reload script bug

    Hi. I know that this seems to be a lot, but trust me it's really not. It's just that its all connected. The actual part you need to help me with is like 1/5 of the script. so i've been rewriting my reload script. I ran into a bug that I can't figure out how to fix. I literally spent 2 hours trying to.. So I wanted to make it so the player will put 2 bullets intro the gun if only 2 bullets are missing from magazine. Or for example i shoot 3 bullets, he will reload 3 bullets. I made 2 animations, first one is inital animation and puts 1 bullet in, and second is just to put 1 bullet in (the second one should be repeated in the process). So lets say the magazine is missing 3 bullets. First we play 1st animation and then 2 times the 2nd one. 1st https://gyazo.com/873545639d40c564bea23142e61d5185 2st https://gyazo.com/d1961991a96b1cc2db97bead4135697c Animator: https://gyazo.com/e76e7e9300fa0605133062f03dba723d Code (Explaination below) using System.Collections; using System.Collections.Generic; using UnityEngine; public class Weapon : MonoBehaviour { //core public bool secondReload = false; private Animator anim; private bool isReloading; private bool isReloading2; public float range = 100f; public int bulletsPerMag = 5; //per magazine public int bulletsLeft = 30; //total bullets left public int currentBullets; //bullets in current mag public Transform shootPoint; float fireTimer; public ParticleSystem muzzleFlash; public float fireRate = 0.1f; //Bullet impact effects public GameObject hitParticlesSand; public GameObject bulletImpact; //sound private AudioSource _AudioSource; public AudioClip shootSound; //damaging private bool shootInput; public float damage = 30f; //aim private Vector3 originalPosition; public Vector3 aimPosition; public float aimSpeed = 8f; void Start() { anim = GetComponent<Animator> (); _AudioSource = GetComponent<AudioSource> (); currentBullets = bulletsPerMag; originalPosition = transform.localPosition; } void Update(){ if (Input.GetButtonDown ("Fire1")) { if (currentBullets > 0) Fire (); //call Fire else if(bulletsLeft > 0) DoReload (); } if (fireTimer < fireRate) fireTimer += Time.deltaTime; //add into the timer if (Input.GetKeyDown (KeyCode.R)) { if(currentBullets < bulletsPerMag && bulletsLeft > 0) DoReload (); } aim (); } private void Fire() { if (fireTimer < fireRate || currentBullets <= 0) return; RaycastHit hit; if (Physics.Raycast(shootPoint.position, shootPoint.transform.forward, out hit, range)) { Debug.Log(hit.transform.name + "found!"); GameObject hitParticleEffect = Instantiate (hitParticlesSand, hit.point, Quaternion.FromToRotation (Vector3.up, hit.normal)); //instantiate = spawn, align to top GameObject bulletHole = Instantiate (bulletImpact, hit.point, Quaternion.FromToRotation (Vector3.forward, hit.normal)); //stop fickering in the impact texture Destroy (hitParticleEffect, 3f); Destroy (bulletHole, 15f); } muzzleFlash.Play (); PlayShootSound (); anim.CrossFadeInFixedTime ("Fire", 0.1f); //play animation currentBullets--; fireTimer = 0.0f; //reset timer if(hit.transform.GetComponent<HitController>()) //if it has controller { hit.transform.GetComponent<HitController> ().DecreaseHealth(); //Access script and call fuction with float damage } } public void DoReload() { AnimatorStateInfo info = anim.GetCurrentAnimatorStateInfo (0); if (secondReload == true) { if (isReloading2) return; anim.CrossFadeInFixedTime ("ReloadBullet", 0.01f); } else { if (secondReload == false) { if (isReloading) return; anim.CrossFadeInFixedTime ("Reload", 0.01f); } } } void FixedUpdate() { AnimatorStateInfo info = anim.GetCurrentAnimatorStateInfo (0); //if (info.IsName ("Fire")) // anim.SetBool ("Fire", false); isReloading = info.IsName("Reload"); isReloading2 = info.IsName("ReloadBullet"); } private void PlayShootSound() { _AudioSource.PlayOneShot (shootSound); //_AudioSource.clip = shootSound; //_AudioSource.Play (); } public void Reload() { if (bulletsLeft <= 0) //no bullets at all return; int bulletsToLoad = bulletsPerMag - currentBullets; //Maybe I'll need it later bulletsLeft -= 1; if (currentBullets < bulletsPerMag) { currentBullets += 1; secondReload = true; DoReload (); } else { secondReload = false; } } private void aim() { if (Input.GetButton ("Fire2") && !isReloading) { transform.localPosition = Vector3.Lerp (transform.localPosition, aimPosition, Time.deltaTime * aimSpeed); //Smoothly moves from localPOS to aimPOS with speed "aimSpeed" } else { transform.localPosition = Vector3.Lerp (transform.localPosition, originalPosition, Time.deltaTime * aimSpeed); } } } When i fire or do R, it jumps to doReload function, There it checks if secondReload is true and if not, plays 1st animation. Script of 1st animation: using System.Collections; using System.Collections.Generic; using UnityEngine; public class ReloadState : StateMachineBehaviour { public float reloadTime = 0.7f; bool hasReloaded = false; // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { hasReloaded = false; } // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (hasReloaded) return; if (stateInfo.normalizedTime >= reloadTime) { animator.GetComponent<Weapon>().Reload(); hasReloaded = true; } } // OnStateExit is called when a transition ends and the state machine finishes evaluating this state override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { hasReloaded = false; } } Then here after animation is finished It calls reload function in above script. There it checks if there are any bullets at all left, if yes then it decreases by 1 bulletsleft value, makes secondReload true, adds 1 bullet/value to the magazine/clip and calls doReload. There it play 2nd animation since secondReload is true. The problem is that when I fire all bullets (5 per magazine/clip), it runs 1st animation once and 2nd animation once. After that i fire those 2 bullets as well and it runs only 1st animation (https://gyazo.com/7d7ca2af00651b0402c8924fe5c60537) Whoever solves this or atleast tries I thank you so much!
  5. Wild West Multiplayer FPS Project

    First of all, thank you for kind words . I will have more done at next update most likely and depth of field will be decreased for sure.
  6. Hey guys! I made Update 1 video of project names Calister showdown. To Do list for a few upcoming updates: - Dynamic reloading anomation - Bug fixes - Ragdoll shoot force - Footstep sounds - Networking - Weapon aiming Please keep in mind that models, scenes and animations will definitely change and are just placeholders at the moment. Leave some feedback if you find it good https://www.youtube.com/watch?v=oMFsQIhZpRY
  7. Enabling/disabling scripts on collision

    Thanks, I had to pu else if statement like you said and rename void update to sail and then call it in the first if statement.
  8. Enabling/disabling scripts on collision

    Hello. This script should disable RigidbodyFirstPersonController and enable BoatController scripts when object with tag "player" enters the collider and presses "E". When "E" is pressed once more, it should enable RigidbodyFirstPersonController and disable boatcontroller. The problem is that it executes all at the same time, disables RigidBodyFirstPersonController and doesn't enable BoatController and when i click "E" again it doesn't enable RigidBodyFirstPersonController back. (image 2) Images: https://gyazo.com/b3740c0ecd4bb5da4b7400f7afe784f4 https://gyazo.com/08e1efbc2ac9325c9828770b21a31638 Script: using UnityEngine; using UnityStandardAssets.Characters.FirstPerson; public class SailZone : MonoBehaviour { public GameObject Schooner; public GameObject Pirate; public KeyCode sailKey; public bool sailState = false; void OnTriggerStay(Collider target) { if(target.tag == "Player") { if (Input.GetKeyDown(sailKey) && sailState == false) { sailState = true; Debug.Log ("Entered the zone"); } if (Input.GetKeyDown(sailKey) && sailState == true) { sailState = false; Pirate = GameObject.FindWithTag ("Player"); Schooner.GetComponent<BoatController>().enabled = false; Pirate.GetComponent<RigidbodyFirstPersonController>().enabled = true; Debug.Log ("Leave"); } } } void Update(){ if (sailState = true && Schooner.GetComponent<BoatController> ().enabled == false) { Schooner.GetComponent<BoatController> ().enabled = true; Pirate = GameObject.FindWithTag ("Player"); Pirate.GetComponent<RigidbodyFirstPersonController>().enabled = false; Debug.Log ("Enabled drive mode"); } } }
  9. Make object mass not affect other objects

    Weird. Only errors are from Post proccessing by Unity which I suppose is normal cause some effects aren't avaible on personal edition of the engine.
  10. Make object mass not affect other objects

    The weird thing is that it works fine when I'm at editor but when i export it, it messes up. Alsomass of the ship is 33k and mass of fthe player is 10
  11. Hi. So how could a code a script or any other way to make player's mass not affact my buoyancy ship. (Ship leans to one side when player stand there)
  12. Not copying project correctly

    I will try to record it as soon as i have some time cause im going on vacation now.
  13. Not copying project correctly

    No it wasn't.
  14. Not copying project correctly

    Im pretty sure it the correct folder and I am 100% sure that it saved correctly cause i opened it many times and changed nothing, just to test the game.
  15. Not copying project correctly

    So everytime i make a backup of a project (I copy folder of the project), when i open the backed up project, there aren't the changes i made last. Its like some major changes behind.