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 eeveelution8 · Mar 16, 2013 at 09:15 PM · c#error

Identifier help

  • seem to have a working script so far, the only errors i have seen is a "cs1041: identifier expected" at lines 45,61,77,93.

anyone know how to fix it? C#*

*FIXED

 using UnityEngine;
 using System.Collections;
 
 
 public class HealthController : MonoBehaviour {
     
     public GameObject deathHandler;
     public float maxHealth = 100;
     public float hitDamage = 3;
     public float healingSpeed = 2;
     public GameObject hitParticles;
     public GameObject MGBullet;
     public GameObject Bullet;
     public GameObject Missile;
     public GameObject Pellet;
     public AudioClip hitSound;
     [HideInInspector]
     public float health;
     
     public float normalizedHealth { get { return health / maxHealth; } }
     
     // Use this for initialization
     void OnEnable () {
         health = maxHealth;
     }
     
     // Update is called once per frame
     void Update () {
         if (Time.deltaTime == 0 || Time.timeScale == 0)
             return;
         
         if (health > 0)
             health += Time.deltaTime * healingSpeed;
         health = Mathf.Clamp(health, 0, maxHealth);
     }
     
     void OnHit (MGBullet @MGBullet) {
         health -= 6;
         health = Mathf.Clamp(health, 0, maxHealth);
         
         if (hitParticles) {
             GameObject particles = Instantiate(
                 hitParticles,
                 MGBullet.hit.point,
                 Quaternion.LookRotation(-MGBullet.direction)
             ) as GameObject;
             particles.transform.parent = transform;
         }
         if (hitSound) {
             AudioSource.PlayClipAtPoint(hitSound, MGBullet.hit.point, 0.6f);
         }
     }
     void OnHit (Bullet @Bullet) {
         health -= 10;
         health = Mathf.Clamp(health, 0, maxHealth);
         
         if (hitParticles) {
             GameObject particles = Instantiate(
                 hitParticles,
                 Bullet.hit.point,
                 Quaternion.LookRotation(-Bullet.direction)
             ) as GameObject;
             particles.transform.parent = transform;
         }
         if (hitSound) {
             AudioSource.PlayClipAtPoint(hitSound, Bullet.hit.point, 0.6f);
         }
     }
     void OnHit (Pellet @Pellet) {
         health -= 9;
         health = Mathf.Clamp(health, 0, maxHealth);
         
         if (hitParticles) {
             GameObject particles = Instantiate(
                 hitParticles,
                 Pellet.hit.point,
                 Quaternion.LookRotation(-Pellet.direction)
             ) as GameObject;
             particles.transform.parent = transform;
         }
         if (hitSound) {
             AudioSource.PlayClipAtPoint(hitSound, Pellet.hit.point, 0.6f);
         }
     }
     void OnHit (Missile @Missile) {
         health -= 100;
         health = Mathf.Clamp(health, 0, maxHealth);
         
         if (hitParticles) {
             GameObject particles = Instantiate(
                 hitParticles,
                 Missile.hit.point,
                 Quaternion.LookRotation(-Missile.direction)
             ) as GameObject;
             particles.transform.parent = transform;
         }
         if (hitSound) {
             AudioSource.PlayClipAtPoint(hitSound, Missile.hit.point, 0.6f);
         }
     }
 }
 


_----------------------------------------------------------- EDIT


i figured out the class thing, but i have a different error now, it thinks that missile, MGBullet, and Bullet are types, but Pellet is a field. how do i get them to be fields?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by robertbu · Mar 16, 2013 at 09:24 PM

When declaring a new method, you need to include the type with the parameters:

 void OnHit (GameObject MGBullet) {

While I don't have the types you intended, I'm assuming all the parameters for all the OnHit() methods are of type GameObject. If so, then you have a problem. You cannot have multiple different methods with the same name and the same signature (i.e have exactly the same number and type of parameters). You can change them to have different names (OnHitMissile(), OnHitPellet(), ...).

Since you have the variables at the top of the script, you likely don't need any parameters for these methods.

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 eeveelution8 · Mar 16, 2013 at 09:29 PM 0
Share

oh i see..

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

10 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

Related Questions

Unfixable Assets/Scripts/PlayerAttack.cs(30,15): error CS1525: Unexpected symbol `private' 1 Answer

Getting index of the smallest number in a list 1 Answer

C# Code errors 1 Answer

Hey guys, im starting do make a RPG game and in the Level system script(I called it "PlayerStatsController") i have an error: Parser Error : Unexpected symbol `public'. My script above: 1 Answer

Burgzergarcade Why am i getting an error after re-importing? 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