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 /
This question was closed Jan 25, 2015 at 05:04 AM by Ujean917 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Ujean917 · Jan 23, 2015 at 08:12 PM · c#sendmessage

SendMessage GatherEnergy has no receiver

Can someone explain to me why this setup I have is incorrect. I believed I had used the SendMessage method correct but the compiler is yelling at me that its not. Thank you for your time.

Here is the two codes I am using:

The first one.

 using UnityEngine;
 using System.Collections;
 
 public class EnemyHealth : MonoBehaviour 
 {
     public float maxHealth = 10.0f;
     private float currentHealth;
     public GameObject deathEffect;
     public GameObject damageEffect;
     public string collisionTag = "PlayerBullets";
 
     public int theEnergy = 20;
     private GameObject secondFormManager;
 
 
     // Use this for initialization
     void Start () 
     {
         currentHealth = maxHealth;
         secondFormManager= GameObject.FindGameObjectWithTag ("SecondFormManager");
     }
 
     void OnTriggerEnter(Collider col)
     {
         if(col.tag == collisionTag)
         {
             currentHealth -= 1.0f;
             Instantiate(damageEffect,col.ClosestPointOnBounds(transform.position), Quaternion.identity);
 
             if(currentHealth <= 0)
             {
                 Instantiate(deathEffect, transform.position, Quaternion.identity);
 
                 Destroy(gameObject);
                             //THE SENDER CODE
                 secondFormManager.SendMessage ("GatherEnergy", 20.0f);
             }
         }
     }
 }


The second one.

 using UnityEngine;
 using System.Collections;
 
 public class ChangeToSecondForm : MonoBehaviour 
 {
     private static ChangeToSecondForm instance = null;
     public static ChangeToSecondForm Instance
     {
         get {return instance; }
     }
 
     private GameObject playerToBeChangedFrom;
     private GameObject playerChangingTo;
 
     public Transform secondFormDisplay;
     public float maxEnergy = 100.0f;
     public float currentEnergy;
     private float energyOriginalXScale;
 
     // Use this for initialization
     void Start () 
     {
         currentEnergy = 0.0f;
         energyOriginalXScale = secondFormDisplay.localScale.x;
         playerToBeChangedFrom = GameObject.FindGameObjectWithTag ("PlayerCharacter");
         playerChangingTo = GameObject.FindGameObjectWithTag ("PlayerCharacterSecondForm");
         playerChangingTo.SetActive (false);
     }
     
     // Update is called once per frame
     void Update () 
     {
         if (currentEnergy <= 0) 
         {
             secondFormDisplay.GetComponentInChildren<Renderer>().enabled = false;
         }
 
         SecondForm ();
     }
 
     public void SecondForm()
     {
         if (Input.GetButtonDown ("TransformToSecond") && (currentEnergy == 100)) 
         {
             Debug.Log("Q has been pressed");
             currentEnergy = 0;
 
             playerToBeChangedFrom.SetActive (false);
             playerChangingTo.SetActive(true);
 
             playerChangingTo.SendMessage ("TransformQueSound", true); 
 
 
             Invoke ("ChangeBack", 10.0f);
         }
     }
 
     public void ChangeBack ()
     {
         playerToBeChangedFrom.SetActive (true);
         playerChangingTo.SetActive (false);
     }
 
 //THE RECEIVING CODE
     public void GatherEnergy(float energyGathered)
     {
         Debug.LogError ("Got Energy from dead enemy.");
         
         currentEnergy += energyGathered;
 
         if (currentEnergy >= 100) 
         {
             currentEnergy = 100.0f;
         }
 
         secondFormDisplay.localScale = new Vector3(energyOriginalXScale * (currentEnergy/maxEnergy), secondFormDisplay.localScale.z, secondFormDisplay.localScale.z);
     }
 }
Comment
Add comment · Show 3
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 Ujean917 · Jan 24, 2015 at 02:21 AM 0
Share

I didn't think that the alternateAttack$$anonymous$$anager would need the script attached. I'll get home to do it and see what I can bring to light from there. UPDATE: I looked at the code one more time to see why you said the thing you did and now I see I have made an incredibly bad typo. This was a silly mistake. Thanks for helping anyhow.

avatar image LessThanEpic · Jan 24, 2015 at 02:54 AM 0
Share

That's most likely the problem. I'll post it as an answer . Let me know if it works.

avatar image Ujean917 · Jan 24, 2015 at 05:40 AM 0
Share

It works better now but I was only able to progress a little. I wasn't sure if I'm allowed to ask two separate questions in one thread because I don't remember from where but something stated a thread was to keep one question in a thread. So the updated script and question is in this link in another thread.

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by LessThanEpic · Jan 23, 2015 at 11:29 PM

Have you verified that your alternateAttackManager game object has the ChangeToSecondForm script attached?

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

Follow this Question

Answers Answers and Comments

20 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

Related Questions

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

An OS design issue: File types associated with their appropriate programs 1 Answer

NGUI Health SendMessage Has No Receiver 1 Answer

Sending a message from javascript to C# 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