- Home /
C# Error help ( error CS0023 The `!’ operator cannot be applied to operand of type `string’ ) ???
Hey guys, I’ve been coding with Unityscript for about 2 years now and so I thought I should move onto C# for some benefits and just to learn something new, and as expected with learning a new language is to get errors, but this one is one that I can’t just search up and find so I’m gonna need more advanced help I guess. The error is this:
line: (19,42) error CS0023: The ‘!’ operator cannot be applied to operand of type ‘string’ .
So really all I’m asking for is an answer to this error and an explanation to why I’m getting it in the first place to stop it in the future. Thanks in advance :) .
using UnityEngine;
using System.Collections;
public class PickupRay : MonoBehaviour {
public GameObject mainPlayer;
public string pickupTagIdentifyer;
public bool picked;
public bool canpick;
public Transform grabTrans;
private RaycastHit hit;
public float maxDistance = 1.4444f;
public float weight = 1.0f;
void Update () {
canpick = false;
if(!picked){
if(!hit.collider.tag == pickupTagIdentifyer || !(hit.collider.GetComponent(PickupObject) == null)){
}
}
}
}
Answer by KiraSensei · May 19, 2014 at 11:39 AM
Try this :
if( !(hit.collider.tag == pickupTagIdentifyer) || !(hit.collider.GetComponent(PickupObject) == null) ){
The ! was "applied" to hit.collider.tag only.
Your answer
Follow this Question
Related Questions
Error CS0023: The '!' operator cannot be applied to operand of type 'void' 1 Answer
NullReferenceException 1 Answer
CSharp Classes = Scripts? Difference between private string and normal string? 1 Answer
Cannot implicitly convert type string to list - Why is this? 1 Answer
Multiple Cars not working 1 Answer