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 laurienash · May 16, 2013 at 01:00 PM · destroythirdpersoncontroller

Third person controller not being destroyed although script works

Hello,

In my game, when a third person controller walks into a box collider - I want to destroy that controller and instantiate a new one.

This is the script I wrote to destroy the first controller:

 var thirdPerson : GameObject;
 
 
 function OnTriggerEnter(other: Collider){
 
   if (other.tag == "Player")
   { 
     Destroy(thirdPerson);
     }
     
     }

And this is the script to instantiate the new one:

 var prefab : Transform;
 
 private var hasPlayed = false;
 
 
 function OnTriggerEnter () {
 
 var pos : Vector3; 
 
 if (!hasPlayed){
 
 Instantiate (prefab);
 
 hasPlayed = true;
 
 }
 
 }

I tested the scripts on two character controllers that I downloaded from the asset store already animated, and they both worked.

However - I've just learnt to animate characters myself (I'm very new to unity) and want to use these instead - but although the new controller is intantiated, the first one isn't destroyed.

I've been through everything I can think of - but I just can't work out why the characters I've animated myself aren't destroyed when the script itself works.

If anyone has any idea why - please help!

Thanks, Laurien

Comment
Add comment · Show 4
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 laurienash · May 16, 2013 at 01:08 PM 0
Share

I forgot to add - all of my scripts are in javascript, but the script I'm using to animate my characters is in C Sharp. (as it was the only tutorial I could find that worked)

Is this the problem do you think? (and if so - how do I go about solving it?)

avatar image dorpeleg · May 16, 2013 at 02:56 PM 0
Share

Try comparing the ones that you animated and the ones you didn't.

If one of them worked and one didn't, there must be a difference.

avatar image laurienash · May 16, 2013 at 03:17 PM 0
Share

The only difference I can find is that the script I used to animate my characters is in C Sharp, unlike the ones I didn't animate, which use javascript.

But I can't work out if this means that I need to need to make changes to the script in C Sharp, or I need to write a new script in javascript?

avatar image dorpeleg · May 16, 2013 at 03:24 PM 0
Share

Try looking at both scripts and see if there are any major differences.

Did you try looking at the log?

It might tell you why it's not destroying.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Safforn · May 16, 2013 at 03:50 PM

well if the script is on the character cotroller, it destroys the script and therefore can't execute it anymore. Try putting the script on an empty gameobject, and on the collider just a trigger with a "sendmessage".

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 laurienash · May 17, 2013 at 03:26 PM 0
Share

The script is on the box collider attached to an empty game object, not the character - so it isn't destroyed - so that shouldn't make a difference?

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

15 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

Related Questions

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Destroy character controller and instantiate new one 1 Answer

Destroying all enemy characters after the level is over 4 Answers

Destroy GameObject With Collision Using C# 1 Answer

Find gameobjects by tag, and destroy if in the distance of a certain game object... 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