- Home /
Interaction with various objects
Hey guys,
When the player is near an interactive object and presses e for argument's sake the following happens: - We do a check to ensure that we don't need to repositioned to do the corresponding action. - If we have to, we move to the attached transform. - Depending on the type of interactive object, we do something.
My problem is with converting GameObject to InteracticeObject in order to access the script of whatever object we're near and pressing E at.
The code for this is below:
//===============================================
//Prompt System
//===============================================
void Update{
if(promptEnabled){
if(Physics.Raycast(playerTransform.position,Vector3.forward, out hit, 50))
{
if(hit.collider.gameObject.tag=="InteractiveObject")
{
if(Input.GetButtonDown("Activate"))
{
PrepareToPrompt(InteractiveObject);
}
}
}
}
}
void PrepareToPrompt(InteractiveObject iO)
{
if(iO.bRequireStanding)
{
MoveTo(iO.standingTransform); //Move to the required position
if(playerTransform.position == iO.standingTransform.position) //When we're at the position do the prompt
{
Prompt(iO);
}
}
else
{
Prompt(iO);
}
}
void Prompt(InteractiveObject iO)
{
switch(iO.oT) //oT is a string variable for "Type"
{
case "Press": //Do something to press break;
}
}
Help would be appreciated :)
Your answer
Follow this Question
Related Questions
Raycast Snapping Problem. 0 Answers
How do i make the object at the end of my raycast not phase into a wall? 2 Answers
Referencing color change when object is 'deselected' 2 Answers
Multiple Cars not working 1 Answer
how can i display a message to the player that they can interact with an object 1 Answer