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 Draconius9898 · Feb 08, 2016 at 12:07 AM · c#scripting problemerrorgameplay

I can't figure this out. I have Unity 5.3.1 and this error keeps popping up. error CS0029

here is the Script: using UnityEngine; using System.Collections;

public class Enemy : MonoBehaviour { public float moveSpeed = 2f; // The speed the enemy moves at. public int HP = 2; // How many times the enemy can be hit before it dies. public Sprite deadEnemy; // A sprite of the enemy when it's dead. public Sprite damagedEnemy; // An optional sprite of the enemy when it's damaged. public AudioClip[] deathClips; // An array of audioclips that can play when the enemy dies. public GameObject hundredPointsUI; // A prefab of 100 that appears when the enemy dies. public float deathSpinMin = -100f; // A value to give the minimum amount of Torque when dying public float deathSpinMax = 100f; // A value to give the maximum amount of Torque when dying

 private SpriteRenderer ren;            // Reference to the sprite renderer.
 private Transform frontCheck;        // Reference to the position of the gameobject used for checking if something is in front.
 private bool dead = false;            // Whether or not the enemy is dead.
 private Score score;                // Reference to the Score script.

 
 void Awake()
 {
     // Setting up the references.
     ren = transform.Find("body").GetComponent<SpriteRenderer>();
     frontCheck = transform.Find("frontCheck").transform;
     score = GameObject.Find("Score").GetComponent<Score>();
 }

 void FixedUpdate ()
 {
     // Create an array of all the colliders in front of the enemy.
     Collider2D[] frontHits = Physics2D.OverlapPointAll(frontCheck.position, 1);

     // Check each of the colliders.
     foreach(Collider2D c in frontHits)
     {
         // If any of the colliders is an Obstacle...
         if(c.tag == "Obstacle")
         {
             // ... Flip the enemy and stop checking the other colliders.
             Flip ();
             break;
         }
     }

     // Set the enemy's velocity to moveSpeed in the x direction.
     GetComponent<Rigidbody2D>().velocity = new Vector2(transform.localScale.x * moveSpeed, GetComponent<Rigidbody2D>().velocity.y);    

     // If the enemy has one hit point left and has a damagedEnemy sprite...
     if(HP == 1 && damagedEnemy != null)
         // ... set the sprite renderer's sprite to be the damagedEnemy sprite.
         ren.sprite = damagedEnemy;
         
     // If the enemy has zero or fewer hit points and isn't dead yet...
     if(HP <= 0 && !dead)
         // ... call the death function.
         Death ();
 }
 
 public void Hurt()
 {
     // Reduce the number of hit points by one.
     HP--;
 }
 
 void Death()
 {
     // Find all of the sprite renderers on this object and it's children.
     SpriteRenderer[] otherRenderers = GetComponentsInChildren<SpriteRenderer>();

     // Disable all of them sprite renderers.
     foreach(SpriteRenderer s in otherRenderers)
     {
         s.enabled = false;
     }

     // Re-enable the main sprite renderer and set it's sprite to the deadEnemy sprite.
     ren.enabled = true;
     ren.sprite = deadEnemy;

     // Increase the score by 100 points
     score.score += 100;

     // Set dead to true.
     dead = true;

     // Allow the enemy to rotate and spin it by adding a torque.
     GetComponent<Rigidbody2D>().constraints = false;
     GetComponent<Rigidbody2D>().AddTorque(Random.Range(deathSpinMin,deathSpinMax));

     // Find all of the colliders on the gameobject and set them all to be triggers.
     Collider2D[] cols = GetComponents<Collider2D>();
     foreach(Collider2D c in cols)
     {
         c.isTrigger = true;
     }

     // Play a random audioclip from the deathClips array.
     int i = Random.Range(0, deathClips.Length);
     AudioSource.PlayClipAtPoint(deathClips[i], transform.position);

     // Create a vector that is just above the enemy.
     Vector3 scorePos;
     scorePos = transform.position;
     scorePos.y += 1.5f;

     // Instantiate the 100 points prefab at this point.
     Instantiate(hundredPointsUI, scorePos, Quaternion.identity);
 }


 public void Flip()
 {
     // Multiply the x component of localScale by -1.
     Vector3 enemyScale = transform.localScale;
     enemyScale.x *= -1;
     transform.localScale = enemyScale;
 }

}

The Error is on (89, 45) plz help

Comment
Add comment · Show 1
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 Draconius9898 · Feb 08, 2016 at 12:08 AM 0
Share

actually its on (76, 29) my bad

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Wrymnn · Feb 08, 2016 at 09:22 AM

Hey, here is very similar problem discussion http://answers.unity3d.com/questions/245913/how-to-fix-error-cs0029-cannot-implicitly-convert.html

Hope it helps.

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

96 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Input Command Issues 0 Answers

I need help working out a C# script with error CS0120 1 Answer

Script errors 1 Answer

Error CS1525: Unexpected symbol 'void' 1 Answer

How to Destroy game object horizontally and vertically , when hit by a Raycast 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