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 /
This question was closed Apr 05, 2016 at 04:52 PM by mewtwodan8 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by mewtwodan8 · Apr 04, 2016 at 08:25 AM · animation2ddestroycoroutineboolean

Destroy Problem

THANKS IN ADVANCE Hi there i'm trying to write a script for my 2D RPG. in this script an object appears in front of the player, goes through an animation sequence before being destroyed however i am getting the smae three errors however i try to approach this. Hope u can help heres the script: using UnityEngine; using System.Collections;

 public class Freeze : MonoBehaviour {
 
     private Animator anmtr;
     private bool used;
 
     // Use this for initialization
     void Start () {
         anmtr = GetComponent<Animator> ();
         used = false;
     
     }
     
     // Update is called once per frame
     IEnumerator Update () {
         if (Input.GetKeyDown (KeyCode.Alpha1)) {
             anmtr.SetBool ("freeze", true);
             yield return new WaitForSeconds (1f);
             anmtr.SetBool ("freeze", false);
             used = true;
             }
     
     }
     void SelfDestruct () {
         if (used) {
             Destroy (GameObject);
         }
         
         
         
 }
 }

thanks again

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

  • Sort: 
avatar image
1
Best Answer

Answer by meat5000 · Apr 04, 2016 at 01:35 PM

You need a lower case 'g' in

 Destroy (GameObject);

Update can not be a Coroutine, I do believe. Make a separate function and make that a coroutine, calling it from Update, instead.

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 mewtwodan8 · Apr 05, 2016 at 03:41 PM 0
Share

Yes that was the problem many thanks

avatar image
0

Answer by Kurtisi · Apr 04, 2016 at 08:48 AM

Which errors does it show? What exactly is not working?

IEnumerator Update? Not quite sure...

 void Update () {
          if (Input.GetKeyDown (KeyCode.Alpha1)) {
              anmtr.SetBool ("freeze", true);
              yield return new WaitForSeconds (1f);
             StartCoroutine(WaitTime());
              }
      
      }
      void SelfDestruct () {
          if (used) {
              Destroy (GameObject);
          }
 
 IEnumerator WaitTime()
 {
              yield return new WaitForSeconds (1f);
              anmtr.SetBool ("freeze", false);
              used = true;
 }

Try this. Maybe it will help.

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 mewtwodan8 · Apr 04, 2016 at 01:30 PM 1
Share

Sorry i could have sworn i put them there before. The three errors i was recieving before were the following:

  • Freeze.cs(28,34): error CS0119: Expression denotes a 'type', where a 'variable', 'value' or 'method group' was expected

  • Freeze.cs(28,25): error CS1502: The best overloaded method match for 'UnityEngine.Object.Destroy(UnityEngine.Object)' has some invalid arguments

  • Freeze.cs(28,25): error CS1503: Argument '#1' cannot convert 'object' expression to type 'UnityEngine.Object' Luckily enough, thanks to your help i am no longer getting those errors however a single new one has appeared: "Freeze.cs(17,14): error CS1624: The body of Freeze.Update()' cannot be an iterator block because void' is not an iterator interface type" Do you know whats going wrong? I typed up exactly what you said.

avatar image Kurtisi mewtwodan8 · Apr 04, 2016 at 07:17 PM 0
Share

Destroy (gameObject);

G shold be small, my mistake. That is my only solution...

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

How to erase message after 3 seconds 1 Answer

Can't seem to get my animations to work proper 1 Answer

Can´t find the infinite loop in this script 0 Answers

My Animator and C-Sharp Bools won't work together? 0 Answers

Changing eye texture using bools 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