Hello, I want to write script so that when I grab a weapon (When I press 1 on keyboard or any other key)
to disable a script that is on another weapon… I already have written system of grabbing weapons…
I had a problem with dealing damage to my enemy because all damages of my weapons are added in between and thats why I wanted to make that script…
using UnityEngine;
using System.Collections;
public class Pistol : MonoBehaviour
{
public int theDamage;
void Update()
{
RaycastHit hit;
EnemyHealth healthComponent;
Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
if (Input.GetMouseButtonDown(0))
{
if (Physics.Raycast(ray, out hit, 100))
{
// gets a reference to the component!
healthComponent = hit.collider.GetComponent<EnemyHealth>();
if (healthComponent == null)
return;
healthComponent.ApplyDamage(theDamage);
Debug.Log("Working");
}
}
}
}