I just made a question post, and Glurth helped me, although I need help again.
I am not sure how to do a damage rate from 25-50, so my gun does a number of damage thru that range. Ill give my code for my robot(Enemy), and my shooting script.
--------------------------
Shooting Script
--------------------------
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class Shooting : NetworkBehaviour {
public RobotScript RobotScript;
public int minWeoponDamage = 25;
public int maxWeoponDamage = 50;
public int weoponRange = 100;
public bool debugMode = true;
public Camera FPSCamera;
private void Update()
{
Ray ray = FPSCamera.ScreenPointToRay (new Vector2 (Screen.width / 2, Screen.height / 2));
RaycastHit hitInfo;
if (debugMode == true)
{
Debug.DrawRay(ray.origin, ray.direction * weoponRange, Color.green);
}
if(Input.GetKeyDown(KeyCode.Mouse0))
{
if(Physics.Raycast(ray, out hitInfo, weoponRange))
{
if(hitInfo.collider.tag == "Enemy"){
RobotScript.instance.Health -= 10;
Debug.Log ("Enemy Hit");
}
}
}
}
}
--------------------------
Robot Script
--------------------------
using UnityEngine;
using System.Collections;
public class RobotScript : MonoBehaviour {
public static RobotScript instance;
public int Health = 100;
public GameObject GameObjectRobot;
static int MaxHealth = 100;
public static int DeathHealth = 1;
void Start () {
instance = this;
}
void Update () {
if (Health < DeathHealth) {
Destroy (GameObjectRobot);
Debug.Log("Enemy should be dead");
}
}
}
--------------------------
Extra Info
--------------------------
The robot has a tag named Enemy.
The robot is NOT a player.
The shooting script is attached to my player game object.
The robot script is attached to a game object.
Thanks for taking your time reading this!
↧