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 Seventh Stealth · Mar 17, 2015 at 08:07 AM · javascriptarrayfor-loop

(20,57): BCE0022: Cannot convert 'EnemyAI[]' to 'EnemyAI'.

 var alert : boolean;
  var caution : boolean;
  var normal : boolean;
  var alertTimer : float;
  var cautionTimer : float;
  var alertTime : float = 30;
  var cautionTime : float = 30;
  //CHASING
  var statusGUI : UI.Text;
  var guardSpawn : Transform;
  //var enemy : GameObject;
  var enemyUnit : GameObject[];
  var enemyAIScript : EnemyAI [];
  var enemyHuntScript : EnemyHunt[];
  
  function Start(){
  enemyUnit = GameObject.FindGameObjectsWithTag("Enemy");
  for(var i : int = 0; i < enemyUnit.Length; i++)
     {
  enemyAIScript[i] = enemyUnit[i].GetComponents.<EnemyAI>();
  enemyHuntScript[i] = enemyUnit[i].GetComponents.<EnemyHunt>();
     }
 //
 // alert = false;
 // caution = false;
 // normal = true;
 
  }
  function Update(){
  
  
  if(alert == true){
         if(alertTimer >= 0){
          print("alert");
          statusGUI.text = "ALERT : "+alertTimer;
          alertTimer -= Time.deltaTime;
          enemyHuntScript.enabled = true;
          enemyAIScript.enabled = false;
      }else{
          //ALERT FINISHED
          //SWITCH TO CAUTION
          ActivateCaution();
          print("CAUTION");
          statusGUI.text = "";
      }
  }
  //CAUTION
  if(caution == true){ 
      if(cautionTimer >= 0){
          print("CAUTION");
          statusGUI.text = "CAUTION : "+cautionTimer;
          cautionTimer -= Time.deltaTime;
      }else{
          //
          alert = false;
          caution = false;
          normal = true;
          statusGUI.guiText.text = "";
      }
  }
  //NORMAL
  if(normal == true){
  
  alert = false;
  caution = false;
  print("Normal");
  alertTimer = 30;
  cautionTimer = 30;
  statusGUI.text = "NORMAL";
    for(var a : int = 0; a < enemyAIScript.Length; a++)
     {
        enemyAIScript[a].enabled = true;
 
     }
  for(var b : int = 0; b < enemyHuntScript.length; b++){
  enemyHuntScript[b].enabled = false;
  }
  }
  
  
  }
  
  
  function ActivateAlert(){
  alert = true;
  alertTimer = alertTime;
  caution = false;
  normal = false;
  }
  
  function ActivateCaution(){
  caution = true;
  cautionTimer = cautionTime;
  alert = false;
  normal = false;
  }



ERROR :Assets/FORCE/Enemies/RegularUnits/ControlAI.js(20,57): BCE0022: Cannot convert 'EnemyAI[]' to 'EnemyAI'.

EERROR :Assets/FORCE/Enemies/RegularUnits/ControlAI.js(20,57): BCE0022: Cannot convert 'EnemyAI[]' to 'EnemyAI'.

Not really sure whats wrong here but I'm getting errors anyway. If you want to see what my script is about read my last question because its the same script(GameController/Manager script)

Thanks Stealth

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
1
Best Answer

Answer by meat5000 · Mar 17, 2015 at 08:23 AM

You are defining a single script for return by placing the i in the square brackets and placing it in a single element by the same method but then you use GetComponents which returns an array.

Use GetComponent

Comment
Add comment · Show 1 · 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 Seventh Stealth · Mar 17, 2015 at 05:25 PM 0
Share

It worked! Thanks bro

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

22 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

Related Questions

Instantiate object in for loop with array 2 Answers

Turn all objects in the array to make same thing 0 Answers

"For"-Loop only works for final element in array 1 Answer

have array target person of most priority/stick with top prior 0 Answers

Tower defense, turret aiming wrong. 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