Question by
ShazBang · Feb 06, 2016 at 02:04 AM ·
javascriptrigidbodyplayer
'OpenClose' is not a member of 'Pushpull' Javascript help
Hey all, I'm trying to learn to code a Jedi type of force code that allows the pushing and pulling of objects.
I'm just having trouble with what I guess is a pretty easy fix.
This is the code for the object:
#pragma strict
public var relativeOpenPos = Vector3(1,0,0);
public var speed = 1.0f;
private var posOpen;
private var posClose;
private var posDest;
private var open = false;
function Start() {
posClose = transform.position;
posOpen = transform.position + relativeOpenPos;
posDest = posClose;
}
function Update() {
var pos = Vector3.MoveTowards(transform.position, posDest, Time.deltaTime * speed);
rigidbody.MovePosition(pos);
}
function OpenClose() {
open = !open;
posDest = open ? posOpen : posClose;
}
and this is the code for the player:
#pragma strict
function Update() {
var hit : RaycastHit;
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Input.GetMouseButtonDown(0)) {
if (Physics.Raycast(ray, hit) && (hit.collider.tag == "PushPull")) {
hit.collider.GetComponent(PushPull).OpenClose();
}
}
}
The title says it all, I'm getting problems with them not being members of each other.
Thanks in advance!
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612063154im_/https://answers.unity.com/themes/thub/images/avi.jpg)