My code is:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Weapon : Mono Script
{
public int damage;
public Camera camera;
public float fireRate;
private float nextFire;
// Update is called once per frame
void Update()
{
if (nextFire > 0)
nextFire -= Time.deltaTime;
if (Input.GetButton("Fire1") && nextFire <= 0)
{
nextFire = 1 / fireRate;
Fire();
}
}
void Fire()
{
Ray ray = new Ray(camera.transform.position, camera.transform.forward);
RaycastHit hit;
if (Physics.Raycast(ray.origin, ray.direction, out hit, 100f))
{
if (hit.transform.GameObject.GetComponent<Health>())
{
hit.transform.GameObject.GetComponent<PhotonView>().RPC("TakeDamage", RpcTarget.All, damage);
}
}
}
}
Im not sure why it wont work.