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 Chamberload · Feb 15, 2017 at 06:27 PM · networkingraycastreturn value

Help with selecting objects through raycast in multiplayer game

Hello, i've been programming for some time now and i decided to start a multiplayer project. It's a 2D rpg game where you battle by selecting enemies and then cast abilities on them. So far everything has gone smoothly by following some toturials and applying what i learned from them to the project, but now i seem to be stuck with an error. The error is: UNetWeaver error: Command function [Raycast:CmdClickSelect] must have a void return type. UnityEngine.Debug:LogError(Object) Unity.UNetWeaver.Log:Error(String) (at C:/buildslave/unity/build/Extensions/Networking/Weaver/Program.cs:20) Unity.UNetWeaver.NetworkBehaviourProcessor:ProcessMethods() (at C:/buildslave/unity/build/Extensions/Networking/Weaver/UNetBehaviourProcessor.cs:1240) Unity.UNetWeaver.NetworkBehaviourProcessor:Process() (at C:/buildslave/unity/build/Extensions/Networking/Weaver/UNetBehaviourProcessor.cs:56) Unity.UNetWeaver.Weaver:ProcessNetworkBehaviourType(TypeDefinition) (at C:/buildslave/unity/build/Extensions/Networking/Weaver/UNetWeaver.cs:1064) Unity.UNetWeaver.Weaver:CheckNetworkBehaviour(TypeDefinition) (at C:/buildslave/unity/build/Extensions/Networking/Weaver/UNetWeaver.cs:1549) Unity.UNetWeaver.Weaver:Weave(String, IEnumerable`1, IAssemblyResolver, String, String, String) (at C:/buildslave/unity/build/Extensions/Networking/Weaver/UNetWeaver.cs:1658) Unity.UNetWeaver.Weaver:WeaveAssemblies(IEnumerable`1, IEnumerable`1, IAssemblyResolver, String, String, String) (at C:/buildslave/unity/build/Extensions/Networking/Weaver/UNetWeaver.cs:1748) Unity.UNetWeaver.Program:Process(String, String, String, String[], String[], IAssemblyResolver, Action`1, Action`1) (at C:/buildslave/unity/build/Extensions/Networking/Weaver/Program.cs:34) UnityEditor.Scripting.Serialization.Weaver:WeaveUnetFromEditor(String, String, String, String, Boolean)

And it also comes out saying: Failure generating network code. UnityEditor.Scripting.Serialization.Weaver:WeaveUnetFromEditor(String, String, String, String, Boolean)

here's the code:

using UnityEngine; using System.Collections; using UnityEngine.Networking;

public class Raycast : NetworkBehaviour {

 public GameObject SelectedEnemy;


 [SerializeField]
 private Frost frostAbility;
 [SerializeField]
 private Fireball fireballAbility;
 [SerializeField]
 private Shockwave shockwaveAbility;

 public bool casting = false;



 void Update()
 {


     if (Input.GetButtonDown("Fire1"))
     {
         //Raycast
         Vector2 rayPos = new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y);
         RaycastHit2D hit = Physics2D.Raycast(rayPos, Vector2.zero, 0f);
         CmdClickSelect(hit.collider.gameObject);
     }
     if (Input.GetKeyDown("1") && SelectedEnemy != null && casting == false)
     {
         StartCoroutine(CastTime(frostAbility.castTime, frostAbility.manaCost, frostAbility.abilityName));
         casting = true;

     }
     if (Input.GetKeyDown("2") && SelectedEnemy != null && casting == false)
     {
         StartCoroutine(CastTime(fireballAbility.castTime, fireballAbility.manaCost, fireballAbility.abilityName));
         casting = true;
     }
     if (Input.GetKeyDown("3") && SelectedEnemy != null && casting == false)
     {
         StartCoroutine(CastTime(shockwaveAbility.castTime, shockwaveAbility.manaCost, shockwaveAbility.abilityName));
         casting = true;
     }
 }

 //wait for casttime
 IEnumerator CastTime(float _castTime, float _manaCost, string _abilityName)
 {
     yield return new WaitForSeconds(_castTime);
     CmdDealEnemyDamage(GetComponent<Player>().magic, _manaCost, _abilityName);
     casting = false;
 }

 //send damage to the selected target
 [Command]
 void CmdDealEnemyDamage(float _damageAmount, float _manaCost, string _abilityName)
 {
     if (GetComponent<Player>().currentMana > _manaCost)
     {
         Debug.Log("Used " + _abilityName);
         SelectedEnemy.GetComponent<Enemy>().RpcEnemyTakeDamage(_damageAmount);
         GetComponent<Player>().currentMana -= _manaCost;
     }
     else
     {
         return;
     }
 }

 //this is where the problem is
 [Command]
 public GameObject CmdClickSelect(GameObject _hit)
 {

     //if enemy is hit select that enemy
     if (_hit && _hit.gameObject.tag == "Enemy" && SelectedEnemy != _hit.gameObject)
     {

         SelectedEnemy.GetComponent<Enemy>().CmdEnemySelectPlayer(this.gameObject);
         Debug.Log(_hit.gameObject.name);
         return _hit.gameObject;
     }
     return null;


 }

}

So if anybody can help me with this error or if someone has a better way of doing this then please answer. Also feel free to tell me if you see i have done something stupid in the script :)

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

0 Replies

· Add your reply
  • Sort: 

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

137 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 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

Raycast Hit on a Server Object? 0 Answers

How can you spawn objects on network using raycast? 0 Answers

Raycast doesnt work for client in netcode 0 Answers

cannot reference parent network identity.netId when applying damage 1 Answer

Understanding UNET 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