Home > other >  The trigger and two scripts
The trigger and two scripts

Time:09-27

Requirements are as follows: set up two objects a and b, needs to trigger after a movement to the specified location b began to exercise, I think we should set up a trigger in the location specified object c, but now the trigger script does not know how to write, mainly is don't know need to be assigned to a or b, my understanding of trigger functions in a script written, but how in the heart of the triggering event b as a result of sports?
Do not know to have clear, wish the great spirit of all stripes,
Here is a snippet of code, the change of the triggering event is a Boolean value, but how will the change of the Boolean value in b as a condition of moving?
 void the Update () 
{
//the transform. The position=new Vector3 (Mathf. Lerp (+ 82.5 f - v * Time. Time, - v * Time. The Time + 82.5 f, Time, Time), 0.5 f, 0).
//using the keyboard control object motion, only in x axis direction
Float x=Input. GetAxis (" Horizontal ");
Float z=Input. GetAxis (" Vertical ");
Vector3 move=new Vector3 (0.5 x, f, z);
* maxSpeed rigidbody. AddForce (move);

}
Private void OnTriggerEnter (starts other)
{
If (other. GameObject. CompareTag (" pick "))
{
Flag=false;
}
}

CodePudding user response:

A mount object script only writing AScript code after pressing the keyboard A motion object function

Object B BScript mount script code only write object B movement function

CScript object C (i.e., the trigger) mount script code to realize the triggering function, OnTriggerEnter, determine the contact object is A, is A call the script BScript movement function

CodePudding user response:

Please post the main adopted, please, where is not clear just ask me,

CodePudding user response:

Thank you, but do you have any questions, I how cscript invokes the function of bscript?

CodePudding user response:

https://www.jianshu.com/p/29205af886bf

CodePudding user response:

The third: GameObject. Find (" script in the object name "). GetComponent<script name & gt; () function name (); This method can be invoked only public type function

CodePudding user response:

Call each other between different script was very basic knowledge, you can find a video courses have a look
  • Related