I am trying to access the ThirdPersonCharacter script (specifically the isPoweredUp variable) that is attached to my mainPlayer object, from the power-up.
The goal is when the player collides with the power up, for it to flag the isPoweredUp, and then destroy the power up object.
Here is what I have done so far:
using UnityEngine;
using System.Collections;
public class pickUp: MonoBehaviour
{
public GameObject mainPlayer;
public GameObject pickupPrize;
public GameObject playerScript;
private ThirdPersonCharacter thirdPersonCharacter;
void Awake() {
mainPlayer = GameObject.FindGameObjectWithTag("Player");
}
void Start()
{
pickupPrize = GameObject.FindGameObjectWithTag("Pickup");
thirdPersonCharacter = mainPlayer.GetComponent<ThirdPersonCharacter>();
}
void OnTriggerStay(Collider thePlayer){
{
thirdPersonCharacter.isPoweredUp = true;
Destroy(pickupPrize);
}
}
}
On my mainPlayer object, I have a public variable called isPoweredUp, currently set to false.
When i try to run this I get the following error:
The type or namespace name ThirdPersonCharacter could not be found
What am I doing wrong here?
EDIT:
This is the ThirdPersonCharacter script attatched to my mainPlayer GameObject:
Using UnityEngine;
namespace UnityStandardAssets.Characters.ThirdPerson
{
[RequireComponent(typeof(Rigidbody))]
[RequireComponent(typeof(CapsuleCollider))]
[RequireComponent(typeof(Animator))]
public class ThirdPersonCharacter : MonoBehaviour
{
[SerializeField] float m_MovingTurnSpeed = 360;
[SerializeField] float m_StationaryTurnSpeed = 180;
[SerializeField] float m_JumpPower = 12f;
[Range(1f, 4f)][SerializeField] float m_GravityMultiplier = 2f;
[SerializeField] float m_RunCycleLegOffset = 0.2f; 6
[SerializeField] float m_MoveSpeedMultiplier = 1f;
[SerializeField] float m_AnimSpeedMultiplier = 1f;
[SerializeField] float m_GroundCheckDistance = 0.1f;
Rigidbody m_Rigidbody;
Animator m_Animator;
bool m_IsGrounded;
float m_OrigGroundCheckDistance;
const float k_Half = 0.5f;
float m_TurnAmount;
float m_ForwardAmount;
Vector3 m_GroundNormal;
float m_CapsuleHeight;
Vector3 m_CapsuleCenter;
CapsuleCollider m_Capsule;
bool m_Crouching;
public bool isPoweredUp;
...
}
}
mainPlayerobject, I have a public variable calledisPoweredUp" is wrong: from the code it looks like you understand, but to be sure this sentence should be "On mymainPlayerobject I have a componentThirdPersonCharacterwith a public variable called isPoweredUp".