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 firasdeep · Oct 21, 2011 at 12:13 PM · c#javascripterror

I can do this in JS or not ???

Hello

I can do this in JS or not ???

YouTube.Tutorial

plz do not tell me learn JS >>> only give me the answer .. I can or not >>> if I can >>> how to do it >> if doesn't >>> that mean the JS is not powerful like C# >>> is this right

.................................................. I try many times and give me error

'Add' is not a member of 'UnityEngine.GameObject[]'. or 'Add' is not a member of 'UnityEngine.Transform[]'. ...........................................................

Thx>>>> anyway..

Comment
Add comment · Show 6
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 CHPedersen · Oct 21, 2011 at 12:17 PM 0
Share

It's true that there are some language specific things you can do in C# that JS doesn't support, but for a beginner, you don't need to worry about them. They won't be a hindrance to you to begin with anyway.

The reason I'm commenting and not answering is that I'm not sure what kind of answer you really expect. If you want to know whether you can target enemies in JS, then the answer is yes. As long as you're a beginner to program$$anonymous$$g, consider the capabilities of all 3 unity supported languages completely equal. What you can accomplish in one, you can accomplish in another as well.

avatar image syclamoth · Oct 21, 2011 at 12:37 PM 1
Share

When I started out, I had the choice between JS and C#. I am endlessly grateful that I chose C#.

avatar image CHPedersen · Oct 21, 2011 at 12:39 PM 0
Share

I concur. But this question is not about personal language preference. It is about what can be accomplished in them.

avatar image syclamoth · Oct 21, 2011 at 12:44 PM 0
Share

I think I misunderstood something in the question, there. I thought that when the OP said "plz do not tell me learn JS" that they knew C# and didn't want to learn JavaScript. I think, that's not it- I think that what they actually meant, was "please, I don't want to learn any program$$anonymous$$g languages, I just want to have the answers handed to me on a plate". Yes, upon rereading, that's definitely what they said.

In which case, my answer is useless to them, in every possible way.

Sorry.

avatar image syclamoth · Oct 21, 2011 at 12:45 PM 0
Share

In any case, I should totally learn Boo just so that I can answer questions like this in it.

Show more comments

2 Replies

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

Answer by Graham-Dunnett · Oct 21, 2011 at 12:43 PM

I have only quickly tested this, but I think it is what you need. If you run into this kind of problem again, it's far quicker for you to post the code that you do have and does not work. To answer you I had to follow along the tutorial and write JS whilst the dude was writing c# which took me around 7 minutes. Possibly I could have corrected your code in 30 seconds.

 import System.Collections.Generic;
 
 var targets : List.<Transform>;
 
 function Start () {
     targets = new List.<Transform>();
     
     AddAllEnemies();
 }
 
 function Update () {
 }
 
 function AddTarget( t : Transform) {
     targets.Add(t);
 }
 
 function AddAllEnemies() {
 
     var gos : GameObject[];
     gos = GameObject.FindGameObjectsWithTag("Enemy");
     
     for (var go : GameObject in gos)  {
         AddTarget(go.transform);
     }
 }
Comment
Add comment · Show 3 · 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 firasdeep · Oct 21, 2011 at 01:03 PM 0
Share

Super Thanks >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

avatar image firasdeep · Oct 21, 2011 at 01:07 PM 0
Share

now I can from this script understand more about JS.. >>>>

thx to anyone help me or try to help

avatar image firasdeep · Oct 21, 2011 at 01:19 PM 0
Share

I was thought that the JS does not need for Import system like C#..

avatar image
1

Answer by syclamoth · Oct 21, 2011 at 12:41 PM

In any case, the specific problem you are trying to solve here, is that arrays in C# are always static, and cannot change their sizes. You should be using generic lists, instead!

 // You need to put this line at the top of the file
 // near the UnityEngine and System.Collections bits-
 using System.Collections.Generic;

then, when you would define the array-

 // instead of Transform[] name = new Transform[length];

 List<Transform> transforms = new List<Transform>();

Then, when you want to add a member to it,

 transforms.Add(newTransform);

You can iterate through that like this-

 foreach(Transform trans in transforms)
 {
     // do some operation on trans
     Debug.Log(trans.position);
 }

You can delete specific transforms out of the list if you need to-

 transforms.Remove(someTransform);

this will remove that transform from the list.

Remember, the 'Generic' in generic list means you can do this for any type! Just replace Transform in the type declaration with whatever type you need.

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 firasdeep · Oct 21, 2011 at 01:03 PM 0
Share

Thx very very much

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

Script not working (Java script) 2 Answers

Play music trough scenes 0 Answers

Fonts not displaying properly when loaded through script 0 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