- Home /
Question by
Treven · May 09, 2016 at 07:22 PM ·
scripting problemvariablescodepageparent-childpassing
Child not accepting variables from the parent
Hi my Child not accepting variables from the parent but the only variable it accepts is the public ints i cant figure out whats wrong here. Everything should work.
private PlayerControls pc;
HitBoxCollider hitBox;
public float knockBackX1;
public float knockBackY1;
public int damageToGive;
Void Start()
{
pc = GetComponent<PlayerControls>();
hitBox = GetComponentInChildren<HitBoxCollider>();
}
void Update ()
{ HitBoxData();
}
void HitBoxData()
{
if (attackCount == 1)
{
//problem here
hitBox.knockBackX = knockBackX1;
hitBox.knockBackY = knockBackY1;
//to here
hitBox.damageToGive = damageToGive;
}
Comment
Did you make sure that knockBackX and knockBackY are public variables in the child's class (HitBoxCollider)? Only public variables are available from outside the script.
I sorry to waste your time but i made a new question that better explains my problem is there a way to send it to you through here. And i have those public already.
I made new question that is better explained but heres the code any way
using UnityEngine; using System.Collections;
public class HitBoxCollider : $$anonymous$$onoBehaviour {
public float knockBackX;
public float knockBackY;
public int damageToGive;
public float knockBackLength;
public GameObject hitBox;
PlayerControls pc;
// Use this for initialization
void Start () {
pc = transform.parent.GetComponentInParent<PlayerControls>();
hitBox.SetActive(false);
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "Enemy")
{
var enemy = other.GetComponent<$$anonymous$$nockBack>();
enemy.knockBackLength = knockBackLength;
enemy.knockBackCount = enemy.knockBackLength;
if (other.transform.position.x < transform.position.x)
enemy.knockFromRight = true;
else
enemy.knockFromRight = false;
if (pc.attackCount > 0)
{
enemy.knockBackX = knockBackX;
enemy.knockBackY = knockBackY;
other.gameObject.GetComponent<Health>().DamageEnemy(damageToGive);
}
}
}
}