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 /
avatar image
0
Question by importguru88 · Apr 13, 2016 at 10:15 AM · c#scripting problemplayeraccesshealth

Error: CS0246 Can't access Player Health Script

I trying trying to access the player health script and I am getting an error . The type or namespace name `CharacterHealth' could not be found. Are you missing a using directive or an assembly reference?

Here is my script :

using UnityEngine; using System.Collections;

public class attack1 : MonoBehaviour { public GameObject player; public GameObject bear; public float distance; private CharacterHealth CharacterHealthScript;

 // Use this for initialization
 void Start () {
 

 
 
 }
 
 // Update is called once per frame
 void Update () {
 player = GameObject.FindWithTag("Player");
 bear = GameObject.Find("bear");
 distance = Vector3.Distance(player.transform.position, bear.transform.position);
 
 if (distance <= 3)
 {    
     GameObject Player = GameObject.FindWithTag("Player");
     CharacterHealthScript = Player.GetComponent<Characterhealth>();
     Characterhealth.Max_Health -= 5f;
     GetComponent<Animation>().CrossFadeQueued("move" , 0.3f, QueueMode.PlayNow);
     GetComponent<Animation>().CrossFade("attack");
 }
 
 else if (distance < 15 && distance > 3.0f){
     GetComponent<Animation>().CrossFadeQueued("attack", 0.3f, QueueMode.PlayNow);
     GetComponent<Animation>().CrossFade("move");
     transform.LookAt(player.transform.position);

     
     
 }
  else 
 

 
 { 
 
 }
 
 }
 
 }


sing UnityEngine;

namespace Opsive.ThirdPersonController { ///

/// Extends the health component by allowing the character to take fall damage. The amount of damage is specified by a curve. /// public class CharacterHealth : Health { [Tooltip("Should fall damage be applied?")] [SerializeField] private bool m_UseFallDamage; [Tooltip("The minimum height that the character has to fall in order for any damage to be applied")] [SerializeField] private float m_MinFallDamageHeight; [Tooltip("A fall greater than this value is an instant death")] [SerializeField] private float m_DeathHeight; [Tooltip("The amount of damage to apply when the player falls by the minimum fall damage height")] [SerializeField] private float m_MinFallDamage; [Tooltip("The amount of damage to apply when the player falls just less than the death height")] [SerializeField] private float m_MaxFallDamage; [Tooltip("A curve specifying the amount of damage to apply if the character falls between the min and max fall damage values")] [SerializeField] private AnimationCurve m_DamageCurve = AnimationCurve.Linear(0, 0, 1, 1);

     /// <summary>
     /// Register for any events that the health should be aware of.
     /// </summary>
     private void OnEnable()
     {
         if (m_UseFallDamage) {
             EventHandler.RegisterEvent<float>(m_GameObject, "OnControllerLand", OnCharacterLand);
         }
     }

     /// <summary>
     /// Unregister for any events that the health was registered for.
     /// </summary>
     private void OnDisable()
     {
         if (m_UseFallDamage) {
             EventHandler.UnregisterEvent<float>(m_GameObject, "OnControllerLand", OnCharacterLand);
         }
     }

     /// <summary>
     /// The character has landed after falling a spcified amount. Determine if any damage should be taken.
     /// </summary>
     /// <param name="fallHeight"></param>
     private void OnCharacterLand(float fallHeight)
     {
         // Return immediately if the fall height is less than the minimum height that the character has to fall in order to start taking damage.
         if (fallHeight < m_MinFallDamageHeight) {
             return;
         }

         var damageAmount = 0f;
         // The fall was too great, specify an infinite amount of damage.
         if (fallHeight >= m_DeathHeight) {
             damageAmount = Mathf.Infinity;
         } else {
             // The fall was somewhere in between the min and max fall height. Use the damage curve to determine how much damage to apply.
             var normalizedHeight = (fallHeight - m_MinFallDamageHeight) / (m_DeathHeight - m_MinFallDamageHeight);
             var damageAmountMultiplier = m_DamageCurve.Evaluate(normalizedHeight);
             damageAmount = m_MinFallDamage + damageAmountMultiplier * (m_MaxFallDamage - m_MinFallDamage);
         }

         // Apply the damage.
         Damage(damageAmount, m_Transform.position, Vector3.zero);
     }
 }

}

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
0

Answer by M-Hanssen · Apr 13, 2016 at 10:46 AM

These are unreadable code snippets ;-) could you please reformat them.

My first guess, is that your missing this on top of your Attack1 script:

 using Opsive.ThirdPersonController;
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

Getting the Player in a Script! 2 Answers

How can I get my Player (which is a square) to move smoothly in Unity 2d? I still need help, even though there are answers. 2 Answers

Player changes scale when i play the game 1 Answer

(C# and Java)Unable to give the Damage from enemy bullet script to Player Health. 3 Answers

Boosting Character Controller Problem 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