Can't reference script.
I'm inside the Joystick script from the CrossPlatformInput package. And I'm trying to call the public Throw function inside my Player script attached to the player object. I have a working reference to the player object but it can't find the script.
public void OnPointerUp (PointerEventData data) //Called when you relese your finger
{
transform.position = m_StartPos;
UpdateVirtualAxes(m_StartPos);
player.GetComponent<Player>().Throw();
}
Edit: I made a test script and did the exact same thing, this works totally fine:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class test : MonoBehaviour {
private GameObject player;
void Start () {
player = GameObject.FindWithTag ("Player");
}
void Update () {
player.GetComponent<Player> ().Throw ();
}
}
is your script called 'Player'? and if so, is it attached the the 'player' gameObject or is it attached to an object that's a child or parent of the player game object? if so, try using GetComponentInChildren/GetComponentInParent
The script is called Player and sits on the player GameObject
Did you put the "Player" class inside of a namespace? I've seen this cause issues.
$$anonymous$$y Player class is not, but i think my Joystick is:
using System;
using UnityEngine;
using UnityEngine.EventSystems;
namespace UnityStandardAssets.CrossPlatformInput
{
public class Joystick : $$anonymous$$onoBehaviour, IPointerDownHandler, IPointerUpHandler, IDragHandler
{
Answer by Supertang · Feb 25, 2018 at 01:35 PM
I tried to remove to Joystick script from the CrossPlatformInput scripts folder and now it works....
I don't understand why it would work that way but at least i figured it out.
Your answer
Follow this Question
Related Questions
videoPlayer Script Help Needed 0 Answers
c# coding question 1 Answer
Using a reference for another script in a method issue. 0 Answers