doesn't seem like it's gonna be answered
Error CS0120 problem
Hello, everyone. I am attempting to make a simple little grappling hook/rope swinging game.
var CJ = this.gameObject.GetComponent(typeof(ConfigurableJoint)) as ConfigurableJoint;
if (Input.GetMouseButtonDown(0))
if (Physics.Raycast(transform.position, Input.mousePosition, 50))
CJ.anchor = RaycastHit.point;
This is the code I have currently. To put it simply, I would like to have it so that the anchor for the configurable joint is set to wherever the player clicks in the game area. I am a complete novice at coding, so, any help and suggestions would be greatly appreciated!
Answer by hexagonius · Jan 28, 2017 at 10:47 AM
Line 5 is wrong. point is a property of an RaycastHit Object, not the RaycastHit class itself. You need to use the Physics.Raycast version with the out hit parameter. Create a RaycastHit variable before raycasting and use it as the out parameter. Then you can access point from that.
Btw.:
var CJ = this.gameObject.GetComponent(typeof(ConfigurableJoint)) as ConfigurableJoint;
==
car CJ = gameObject.GetComponent<ConfigurableJoint>();
Thank you for the reply! I'm grasping it a bit better now, but I'm still having trouble implementing it. If it's not too much trouble, may I ask what you mean by the out hit parameter? I can't seem to do it correctly. (I did get a variable for RaycastHit working, though.)