Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by MamoruK · Apr 17, 2014 at 10:20 PM · arraysstring

Assets/Scripts/Enemy.cs(61,44): error CS1955: The member `UnityEngine.GameObject.tag' cannot be used as method or delegate

i'm just stuck... here's my code

 enter code hereusing UnityEngine;
 using System.Collections;
 
 public class Enemy : MonoBehaviour 
 {
 
     static bool go_left = false;
     private int timer = 300;
     private int rand_num;
     static int num_chosen;
     public GameObject Enemy_bullet;
     public float speed;
 
     void Start()
     {
 
     }
     
     // Update is called once per frame
     void Update () 
     {
         if(go_left)
             transform.position = transform.position + new Vector3 (-.25f, 0, 0);
         else
             transform.position = transform.position + new Vector3 (.25f, 0, 0);
 
         timer -=1;
 
         if (timer <2)
         {
             rand_num = Random.Range(0, 20);
             num_chosen = rand_num;
 
             if (num_chosen == 2)
             {
                 Instantiate(Enemy_bullet, transform.position, transform.rotation);
                 Vector3 newPosition = transform.position;
                 newPosition.y -= speed * Time.deltaTime;
                 transform.position = newPosition;
             }
             timer = 300;
         }
     }
 
     void OnTriggerEnter(Collider col)
     {
         if(col.gameObject.name == "Left_Wall")
         {
             go_left = false;
             MoveDown();
         }
         else if (col.gameObject.name == "Right_Wall")
         {
             go_left = true;
             MoveDown();
         }
     }
     void MoveDown()
     {
         string[] enemies = new string[1] {"aliens"};
         string aliens = GameObject.FindGameObjectsWithTag("Enemy");
         foreach (var entity in enemies)
             transform.position = transform.position + new Vector3 (0, -.5f, 0);
     }
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by robertbu · Apr 17, 2014 at 10:21 PM

GameObject.FindGameObjectsWithTag() returns an array of GameObjects. So the line should read:

  GameObject[] aliens = GameObject.FindGameObjectsWithTag("Enemy");

'aliens' is local, and you are not currently using it, so I'm not sure of the intent of this particular line of code.

P.S. The error you list is not what I would expect from this code, though the line is clearly wrong. Are you sure this exact code generated that error?

Comment
Add comment · Show 5 · 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 MamoruK · Apr 18, 2014 at 05:20 AM 0
Share

yup copy and pasted from unity

avatar image MamoruK · Apr 18, 2014 at 05:33 AM 0
Share

changed up the coding to this

 void $$anonymous$$oveDown()
     {
         GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy");
         foreach (var entity in enemies)
             transform.position = entity.transform.position + new Vector3 (0, -.5f, 0);
     }

so now it kind of works but it buched them together. this is for a space invaders project btw. the section of code is to get all the aliens to move down at once.

avatar image robertbu · Apr 18, 2014 at 05:35 AM 0
Share

If that is the goal (moving the enemies) then your final line does not seem to be right to me. Try this ins$$anonymous$$d:

  entity.transform.position = entity.transform.position + new Vector3 (0, -.5f, 0);
avatar image MamoruK · Apr 18, 2014 at 05:38 AM 0
Share

AHA! that did it thank you!

avatar image robertbu · Apr 18, 2014 at 05:53 AM 0
Share

If you question is answered, please click on the checkmark next to the answer to close it out. Thanks.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How do I convert Component[] array into String[] with GetComponentsInChildren? 1 Answer

Multiple Choice Game of Questions stored in an array 1 Answer

Sequence Scripting 2 Answers

Get multiple variables through a string. 2 Answers


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