Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by PokeRwOw · Sep 20, 2015 at 07:59 AM · destroy

Translation js to C # : just one line in file

I'm actually working to translate a unity project originally in unityscript/javascript to C#. I already have translated a good part of the project, but i'm confronted to one problem :

In javascript, I have a file named KillParticle.js and in this one there is just one line :

 Destroy ( this.gameObject, 1.0);

But if I'm doing the same in C#, Its throwing me an error. How to deal with that in C#? I need to implement this line in Update or Start function ?

Thanks per advance!

PokeRwOw

EDIT :

My KillParticle.cs :

 using UnityEngine;
 using System.Collections;
 
 public class KillParticle : MonoBehaviour {
     Destroy ( this.gameObject, 1.0f);
 }

Return : The method must have a return type. If I insert the Destroy in a function Start or Update it working but I need to implement the code in which function ?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by Xarbrough · Sep 20, 2015 at 08:01 AM

You really should supply us with the full error message, but I assume the compiler doesn't like you using a double instead of a float: Use 1.0f to indicate a float value in c#. (1.0 is a double - a number with twice the precision of a standard float). Also, you actually need to call Destroy() from within a method.

 public class KillParticle : MonoBehaviour
 {
     private void Start()
     {
         Destroy(gameObject, 1.0f);
     }
 }

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 PokeRwOw · Sep 20, 2015 at 06:08 PM 0
Share

Hey ! Thanks for your answer :) But I already did this in my code, I have edited with the error returned.

avatar image Xarbrough · Sep 20, 2015 at 06:13 PM 0
Share

Sorry, I totally missed, that you missed to wrap your Destroy() call in a method. Unity needs to know when to execute the Destroy call, so you can place it either in Awake, Start or somewhere in the Update loop for example. Edited my previous answer. Awake is called first, then Start right before the first frame of the game is renderer. Update is a loop which is called every frame. So if you want to destroy your GameObject 1 Second after it is created, you can call it in Start.

avatar image PokeRwOw · Sep 21, 2015 at 08:59 AM 0
Share

I just want to Destroy the gameobject, when I fire the file $$anonymous$$illParticle

avatar image
0

Answer by Runalotski · Sep 21, 2015 at 11:22 AM

in c# you need to say what the return type of the function is so it would be

 public void death()
 {
     Destroy(gameObject, 1.0f);
 }

where void is the return type wich means it returns nothing where you can have differnt return typs like int

 private int addNumber(int a, int b)
 {
     int x = a + b;
 
     return x;
 }

I think you can use any type as a return like arrays and custom classes

but if you just want a function to do something then using void is what you want

Sorry i was ment to post this as a comment to PokePoWo's Edit but i clicked the wrong place.

Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Using foreach to remove and delete bullet in List - C# 3 Answers

Enemies/GameObject disappearing after initial animation 0 Answers

if the ball hits the coin the coin need to be destoyed but how? i have this but it does not work. 2 Answers

I "m having some issues . How do I get the don't destroy on load to work in C# ? 0 Answers

Static Gameobjects Destroy on Reload 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