I was confortable in JavaScript making my Aim System, but unfortunately i discovered that i NEED to use C# on this, so i rewrited the script. The problem is that it is the biggest mass i’ve ever seen. I am a beginner at C# and i am learning about it, so this might be an easy thing but i don’t know how to solve it =P
Have you ever seen a box inside a box inside another box? It’s basically the same thing here. I want to make a script attached to an aim in which When the player click with the left mouse button, the script will detect if there is something colliding with the aim. If there IS something colliding with the aim, and that thing has the tag “Enemy”, then a log will be displayed for testing purposes.
But i ended up making this mess:
using UnityEngine;
using System.Collections;
public class AimSys : MonoBehaviour
{
bool Click; //This is a trigger.
public float fireRate = 0.5F; //Fire rate.
private float nextFire = 0.0F; //Fire rate.
void Update()
{
if (Input.GetButton("Fire1") && Time.time > nextFire) //Shoots on fire rate. I've set it up to 2 seconds before shooting again.
{
Click = true; //If the player has shoot, THEN:
}
}
void OnCollisionEnter(Aim collision) //This is where it gets a mess. This was supposed to detect if there is anything in the aim's collision area and THEN:
{
if (Click) // IF the player has shoot, THEN:
{
if (Aim.gameObject.tag == "Enemy") // Find if the object colliding with the aim is actually an enemy by finding it's tag.
{
Debug.Log("TARGET HIT!"); //This is where i will implement the health reduction.
}
}
}
}
Can someone help me removing some {} and making it actually work? I would appreciate it. Principally by removing some keys or whatever is it called (Not my mother language sorry) This wouldn’t happen if i was using Java =C