- Home /
I get an error for a reason i dont know
This error : Assets/Multiplayer_manager.cs(58,9): error CS0428: Cannot convert method group GetComponent' to non-delegate type
UnityEngine.GameObject'. Consider using parentheses to invoke the method
using UnityEngine;
using System.Collections;
public class Multiplayer_manager : MonoBehaviour {
public static GameObject Myplayer;
public static GameObject Myplayer2;
void Start () {
GameObject Myplayer = GameObject.FindGameObjectWithTag ("Enemy");
Connect ();
}
void Connect() {
PhotonNetwork.ConnectUsingSettings( "V.02" );
}
void OnJoinedLobby() {
Debug.Log ("OnJoinedLobby");
PhotonNetwork.JoinRandomRoom ();
}
void Update () {
}
void CreateRoom () {
}
void OnPhotonCreateGameFailed() {
return;
}
void OnPhotonRandomJoinFailed() {
Debug.Log ("OnPhotonRandomJoinFailed");
PhotonNetwork.CreateRoom( null );
Debug.Log ("Roomname created");
}
void OnJoinedRoom() {
Debug.Log ("OnJoinedRoom");
Myplayer = Myplayer.GetComponent<Birdmovement>;
Debug.Log (Myplayer);
}
}
I a) formatted your script for you. Please read the FAQ and watch the tutorial video to learn how to do this.
b) added the tag cs0428 to your question. This will help others find the problem.
Answer by Graham-Dunnett · Jun 23, 2015 at 01:21 PM
The error is line 53. Not sure why your compiler error has a different line - probably related to how the code is structured.
Line 53 says "grab the Birdmovement
component and assign it to the GameObject
called Myplayer
. These types are different.
The thing i want to do is like you have 2 players with 2 scripts (same) and if tag , if joined a room if tag = enemy then deactivate the enemys movement script "Birdmovement" thats what i want to acomplish.
Answer by joranc · Jun 24, 2015 at 07:16 AM
I want to like if joined then if tag = "enemy" get the bridmovement script component disable it
Answer by DiegoSLTS · Jun 24, 2015 at 12:11 AM
One problem, like Graham said, is that you're using:
GetComponent<Birdmovement>
which returns a Birdmovement object and are storing it into a GameObject variable.
The other problem (the one your error message is telling you about) is that you forgot the parenthesis in that line. Without the parenthesis instead of calling a method you're trying to use that method as a delegate.
Create another variable of type Birdmovement and change line 53 to:
ThatNewVariable = Myplayer.GetComponent<Birdmovement>();
Your answer
Follow this Question
Related Questions
New to Unity, Noob 3 Answers
Making the leap - How to get into Unity development? 3 Answers
Is it possible to start making a game without any experience in programming? 5 Answers
What does Unity need? 1 Answer
Making my first game? 3 Answers