Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

I have a script with a few errors and I don't know how to fix them.

RestlessMangoRestlessMango Member
edited December 2021 in Brackeys' Tutorials

My errors are: " 'float' does not contain a definition for 'time' and no accessible extension method 'time' accepting a first argument of type 'float' could be found (are you missing a using directive or an assembly reference?)".


Here's The Code

using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class Weapon : MonoBehaviour {


  public float FireRate = 0;

  public float Damage = 10;

  public LayerMask WhatToHit;


  float TimeToFire = 0;

  Transform FirePoint;


  // Start is called before the first frame update

  void Awake(){

    FirePoint = transform.Find ("FirePoint");

    if (FirePoint == null) {

      Debug.LogError("There is No FirePoint");

    }

  }


  // Update is called once per frame

  void Update() {

    if (FireRate == 0) {

      if (Input.GetButtonDown ("Fire1")) {

        Shoot();

        Debug.Log ("Test");

      }

    }

    else {

      if (Input.GetButton ("Fire1") && Time.time > TimeToFire) {

        TimeToFire = TimeToFire.time + 1 / FireRate;

        Shoot();

      }

    }

  }


  void Shoot() {

    Vector2 mousePosition = new Vector2(Camera.main.ScreenToWorldPoint (Input.mousePosition).x, Camera.main.ScreenToWorldPoint (Input.mousePosition).y);

    Vector2 FirePointPosition = new Vector2(FirePoint.position.x, FirePoint.position.y);

    RaycastHit2D hit = Physics2D.Raycast (FirePointPosition, mousePosition - FirePointPosition, 100, WhatToHit);

    Debug.DrawLine (FirePointPosition, (mousePosition-FirePointPosition)*100, Color.cyan);

    if (hit.collider != null) {

      Debug.DrawLine(FirePointPosition, hit.point, Color.red);

    }

  }

}

Sign In or Register to comment.