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
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.
Your answer
Follow this Question
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