Skip to content

Instantly share code, notes, and snippets.

@kubawich
Created March 25, 2017 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kubawich/06821c43db2c8b0594810d03453a216b to your computer and use it in GitHub Desktop.
Save kubawich/06821c43db2c8b0594810d03453a216b to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShootingHabit : MonoBehaviour {
public static ShootingHabit Instance;
bool hasWeapon;
public Animator animator;
public Transform HandPosition;
private void Awake()
{
Instance = this;
animator = GetComponent<Animator>();
hasWeapon = false;
}
private void Update()
{
if (hasWeapon)
{
animator.SetLayerWeight(1, 1);
}
}
void SetWeapon(GameObject weaponObject)
{
Instantiate((Object)weaponObject, new Vector3(HandPosition.transform.position.x, HandPosition.transform.position.y, HandPosition.transform.position.z), Quaternion.identity);
}
private void OnTriggerEnter(Collider other)
{
GameObject.Destroy(other.gameObject);
SetWeapon(other.gameObject);
hasWeapon = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment