- Home /
How to access hinge joint variables
Hi everyone ive got a problem with HingeJoints... I want to activate the hinge joint motor via script but i dont get access to the variables. The script is attached directly to the object( in this case its a door). This is the error Log: /HoH_DoorOpener.cs(51,24): error CS1612: Cannot modify the return value of `UnityEngine.HingeJoint.motor' because it is not a variable
I dont know what to do to access theese variables. If enyone could help me i would be very happy :)
using UnityEngine; using System.Collections;
public class HoH_DoorOpener : MonoBehaviour {
public int sizeX = 50;
public int sizeY = 50;
public float iAppearDistance = 3;
public Transform FPSPlayer;
public Texture2D HandSymbol;
Vector3 mousePos = new Vector3(0, 0, 0);
float fDistance = 0;
bool doWindow = false;
void Update()
{
fDistance = Vector3.Distance(transform.position, FPSPlayer.position);
print(fDistance);
if (fDistance <= iAppearDistance)
{
doWindow = true;
}
else
{
doWindow = false;
}
if (Input.GetMouseButton(0) && doWindow)
{
//Here is the problem, where i cant access the variables...
hingeJoint.motor.force = 10;
hingeJoint.motor.targetVelocity = 10;
hingeJoint.motor.freeSpin = true;
print("Opening Door...");
}
if (Input.GetMouseButton(1) && doWindow)
{
//similar problems at this point ^^
print("Closing Door...");
}
}
void OnGUI()
{
if (doWindow)
{
GUI.Label(new Rect(Screen.width / 2, Screen.height / 2, sizeX, sizeY),
HandSymbol);
}
}
}
Answer by qJake · Sep 10, 2010 at 07:26 PM
First off, make sure that this script is attached to the same Game Object that has the Hinge Joint. If that doesn't work, try this code:
JointMotor m = new JointMotor();
m.force = ...;
m.targetVelocity = ...;
m.freeSpin = ...;
hingeJoint.motor = m;
I used: Joint$$anonymous$$otor motor = hingeJoint.motor; motor.force += 10f; hingeJoint.motor = motor;
Answer by alee26 · Aug 01, 2012 at 11:16 AM
maybe the game engine can't convert the numbers, try like 10f... Bad english, sorry.
Answer by Quaker_SDR · Jun 25, 2013 at 10:40 AM
Assigning the value at runtime, Dont affect "Hingejoint" Motor..!!??
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Accessing a script in Assets folder from Standard Assets Folder 1 Answer
Call function from other script 0 Answers
having a hadtime with script access 1 Answer
Side scroller, Scripting Bike Controls using hinge joints 0 Answers