Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

Help Wanted Non-invocable member

Discussion in 'Animation' started by iswminecraft, Jul 3, 2021.

  1. iswminecraft

    iswminecraft

    Joined:
    Jun 23, 2021
    Posts:
    2
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class DoorRaycast : MonoBehaviour
    7. {
    8.     [SerializeField] private int rayLength = 5;
    9.     [SerializeField] private LayerMask layerMaskInteract;
    10.     [SerializeField] private string excludeLayerName = null;
    11.  
    12.     private MyDoorController raycastedObj;
    13.  
    14.     [SerializeField] private KeyCode openDoorKey = KeyCode.F;
    15.  
    16.     [SerializeField] private Image crosshair = null;
    17.     private bool isCrosshairActive;
    18.     private bool doOnce;
    19.  
    20.     private const string interactableTag = "InteractableObject";
    21.  
    22.     private void Update()
    23.     {
    24.         RaycastHit hit;
    25.         Vector3 fwd = transform.TransformDirection(Vector3.forward);
    26.  
    27.         int mask = 1 << LayerMask.NameToLayer(excludeLayerName) | layerMaskInteract.value;
    28.  
    29.         if(Physics.Raycast(transform.position, fwd, out hit, rayLength, mask))
    30.         {
    31.             if(hit.collider.CompareTag(interactableTag))
    32.             {
    33.                 if(!doOnce)
    34.                 {
    35.                     raycastedObj = hit.collider.gameObject.GetComponent<MyDoorController>();
    36.                     CrosshairChange(true);
    37.                 }
    38.  
    39.                 isCrosshairActive = true;
    40.                 doOnce = true;
    41.  
    42.                 if (Input.GetKeyDown(openDoorKey))
    43.                 {
    44.                     raycastedObj.PlayAnimation();
    45.                 }
    46.             }
    47.         }
    48.  
    49.         else
    50.         {
    51.             if(isCrosshairActive)
    52.             {
    53.                 CrosshairChange(false);
    54.                 doOnce(false);
    55.             }
    56.         }
    57.        
    58.     }
    59.  
    60.     void CrosshairChange(bool on)
    61.     {
    62.         if (on && !doOnce)
    63.         {
    64.             crosshair.color = Color.red;
    65.         }
    66.         else
    67.         {
    68.             crosshair.color = Color.white;
    69.             isCrosshairActive = false;
    70.         }
    71.     }
    72. }
    73.  
    im pretty new to c# , im trying to make a interactable door and i keep getting this error any fixes?

    Non-invocable member 'DoorRaycast.doOnce' cannot be used like a method.
     
  2. Epsilon_Delta

    Epsilon_Delta

    Joined:
    Mar 14, 2018
    Posts:
    128
    You are trying to invoke doOnce as if it was a method, but doOnce is a field. If you want to set it to false, do it as you did it on the line 40:
    doOnce = false;
     
  3. iswminecraft

    iswminecraft

    Joined:
    Jun 23, 2021
    Posts:
    2
    THANK YOU SO MUCH <33
     
unityunity