using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Shooting : MonoBehaviour
{
public float fireRate = 0;
public float Damage = 10;
public LayerMask notToHit;
private float timeToFire = 0;
Transform shootingPoint;
// Use this for initialization
void Start ()
{
shootingPoint = transform.FindChild ("ShootingPoint"); // <---error here
if (shootingPoint == null) {
Debug.LogError ("No ShootingPoint? WHAT?!?!"); // <---error here
}
}
// Update is called once per frame
void Update ()
{
if (fireRate == 0) {
if (Input.GetButtonDown ("Fire1")) {
Shoot ();
}
} else {
if (Input.GetButtonDown ("Fire1") && Time.time > timeToFire) {
timeToFire = Time.time + 1 / fireRate;
Shoot ();
}
}
}
void Shoot ()
{
Vector2 mousePosition = new Vector2 (Camera.main.ScreenToWorldPoint (Input.mousePosition).x, Camera.main.ScreenToWorldPoint (Input.mousePosition).y);
Vector2 shootingPointPosition = new Vector2 (shootingPoint.position.x, shootingPoint.position.y);
RaycastHit2D hit = Physics2D.Raycast (shootingPointPosition, mousePosition - shootingPointPosition, 100, notToHit);
Debug.DrawLine (shootingPointPosition, mousePosition);
}
}
THIS IS REALLY ANNOYING!!! I searched all over unity answers for the answer to (Object reference is not set to instance of an Object c#) whenever i click the button for shooting it pops up i found some other people with the error on unity answers but had a completely different script and i couldnt understand someone plllleeeaaaseee help me. The game im making is for school i really need an answer for this.
↧