- Home /
The question is answered, right answer was accepted
Hi, getting error cs1041 in my code:identifier expected, "this" is a keyword; need solution please
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class recurso : MonoBehaviour {
int id;
bool dentrodelradio;
public bool apuntando;
void OnTriggerEnter(Collider other){
if (other.gameObject.name == "recurso")
dentrodelradio = true;
else dentrodelradio = false;
}
// Use this for initialization
void Start () {
if (this.gameObject.CompareTag("arbol")) {
int id = 1;
}
else if (this.gameObject.CompareTag("carne")) {
int id = 2;
}
}
// Update is called once per frame
void Update () {
if (dentrodelradio){
switch(id){
case 1:
transform.this.gameObject.tag = "arbolactivo";
case 2:
transform.this.gameObject.tag = "carneactivo";
}
if (apuntando){
if (Input.GetMouseButton(0)){
//ir cambiando la textura con un time delta time y un switch.
}
}
}
}
}
Answer by $$anonymous$$ · Aug 26, 2017 at 12:49 AM
Does this work for you:
private int id;
private bool dentrodelradio;
public bool apuntando;
void OnTriggerEnter(Collider other)
{
if (other.gameObject.name == "recurso")
dentrodelradio = true;
else dentrodelradio = false;
}
// Use this for initialization
void Start()
{
if (this.gameObject.CompareTag("arbol"))
{
id = 1;
}
else if (this.gameObject.CompareTag("carne"))
{
id = 2;
}
}
// Update is called once per frame
void Update()
{
if (dentrodelradio)
{
if (id == 1)
this.gameObject.transform.tag = "arbolactivo";
else if (id == 2)
this.gameObject.transform.tag = "carneactivo";
if (apuntando)
{
if (Input.GetMouseButton(0))
{
//ir cambiando la textura con un time delta time y un switch.
}
}
}
}
Answer by TheSOULDev · Aug 26, 2017 at 12:50 AM
You can't use this like that, either put it before transform (which is redundant as transform without it implies you are talking about this) along with the rest (so the whole this.gameObject.tag), or remove transform.
Transform doesn't have a property that is this or gameObject.
Follow this Question
Related Questions
Why does my bullet prefab get destroyed? 1 Answer
Checking for closest gameobject with tag. 5 Answers
Issue with GameObject has been destroyed but it is not destroyed 1 Answer
what is the purpose of 'tags' in an empty game object? 1 Answer
Change gameobject tag when player collides with another gameobject 1 Answer