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 Didymos · Jan 03, 2011 at 09:09 PM · javascriptaidisablewaypoint

What should I do? Disable the AI or have the AI simply be recylced and reused?

I am new to game development and I was just trying to at least make a demo or a full game of a tiny tower defense game. Anyways I was going to have some AI come out and then eventually reach their target at which they then disappear, However My script doesn't really work. What do you think I should do? I tried adding a disable script to my AI Once the AI completes the waypoints, but it doesn't work. It gives me two errors

  1. Assets/Scripts/ExampleScript.js(5,69): BCE0005: Unknown identifier: 'EvilCube'.

  2. Assets/Scripts/ExampleScript.js(21,6): BCE0019: 'EvilCube' is not a member of 'ExampleScript.

EvilCube is the enemy AI that I am trying to disable, once it has completed the waypoints

The EvilCube has successfully gone to the waypoint, but when I add the disable part it gives me several errors

Here is the Script

var waypoint : Transform;

var speed : float = 20;

var distanceToTarget : float = Vector3.Distance(transform.position, EvilCube);

function Update() {

var target : Vector3 = waypoint.position;

var moveDirection : Vector3 = target - transform.position;

var velocity = rigidbody.velocity;

if(moveDirection.magnitude < 1){

velocity = Vector3.zero;

if(distanceToTarget == 0)

this.EvilCube.active = false;

}

else{

velocity = moveDirection.normalized * speed;

}

rigidbody.velocity = velocity;

}

Thanks for the help.

By the way, I put the script on the GameObject "EvilCube" so in INSPECTOR I see the script, plus the waypoints and how fast I can set it, etc..

I am using JavaScript

I want to simply disable the EvilCube.

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

Answer by PrimeDerektive · Jan 03, 2011 at 09:20 PM

If you want to disable the whole gameobject in the scene, you just use:

this.gameObject.active = false; //you actually have to type gameObject

If you wanted to disable this script, but keep the object that had this script in this scene, you would say:

this.enabled = false;

If you wanted to destroy the GameObject from the scene, you would say:

Destroy(this.gameObject);
Comment
Add comment · Show 2 · 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 Didymos · Jan 03, 2011 at 09:23 PM 0
Share

Sorry for spam$$anonymous$$g. I just needed to know all the details. Thanks for helping me. +1 for the help.

avatar image Didymos · Jan 03, 2011 at 09:30 PM 0
Share

Well I read your answer and I decided to apply the first part "this.gameObject.active = false" and it worked. Best Answer.

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

No one has followed this question yet.

Related Questions

How do I create a simply disable script for enemy AI once it completes its waypoints? 2 Answers

AI controller script, Enemy movement issues 0 Answers

Kind of Patrol AI with Point A and B Help 1 Answer

create shortest AI path from/to object. 1 Answer

iTween Help Please MoveTo not working 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