Search Unity

Question trying to get damage script working using navmesh

Discussion in 'Navigation' started by shadowgamer24, Nov 9, 2020.

  1. shadowgamer24

    shadowgamer24

    Joined:
    Jun 26, 2020
    Posts:
    5
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.AI;

    public class attac : MonoBehaviour
    {
    private NavMeshAgent agent;
    public float damagerange = 4f;
    private int index;
    private float speed, agentSpeed;
    private Transform player;
    public float patrolTime = 10f;
    public float aggroRange = 10f;
    public Transform[] waypoints;

    // Start is called before the first frame update
    private void Awake()
    {
    agent = GetComponent<NavMeshAgent>();
    if (agent != null) { agentSpeed = agent.speed; }
    player = GameObject.FindGameObjectWithTag("Player").transform;
    index = Random.Range(0, waypoints.Length);

    InvokeRepeating("Tick", 0, 0.5f);

    }

    if (player != null && Vector3.Distance(transform.position, player.position) < damagerange)
    {
    print("pew pew");
    }
    }
     
  2. shadowgamer24

    shadowgamer24

    Joined:
    Jun 26, 2020
    Posts:
    5
    it says print pew pew just to test it works
     
  3. shadowgamer24

    shadowgamer24

    Joined:
    Jun 26, 2020
    Posts:
    5
    the error's I'm getting are
    CS1519:Invalid token 'if' in class
    CS8124
    CS1026:expected
    CS1519: Invalid token '!=' in class
    CS1519: Invalid token '(' in class
    CS1519: Invalid token '<' in class
    CS1519: Invalid token ')' in class
    CS1001: Identifier expected
    CS1022: Type or namespace definition, or end-of-file expected
    i know there are a lot
     
  4. Skynet766

    Skynet766

    Joined:
    Sep 13, 2020
    Posts:
    22
    The semicolon after InvokeRepeating("Tick", 0, 0.5f); looks like it closes the Awake() method.


    This means your if () is not inside the method, it is inside the class declaration.

    Therefore "Invalid token 'if' in class"