Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Aug 26, 2017 at 12:56 AM by Trick_Shot_Magic for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Trick_Shot_Magic · Aug 26, 2017 at 12:43 AM · gameobjecterror messagetagsthis

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.
             }
         }
     }
         
 }

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

  • Sort: 
avatar image
-1

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.
             }
         }
     }

 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Trick_Shot_Magic · Aug 26, 2017 at 12:51 AM

thanks, think it will work now

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Follow this Question

Answers Answers and Comments

69 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges