// Use this for initialization void Start() { moveBetweenPoints = gameObject.GetComponent <MoveBetweenPoints>(); timer = 0; timeToReset = Random.Range(min, max); min = 3; max = 7; start = moveBetweenPoints.agent.transform.position; }
public void spawnFish() { GameObject prefabToSpawn = prefabToSpawns[Random.Range(0, prefabToSpawns.Length)]; //create new fish currentFish = Instantiate(prefabToSpawn, transform.position, Quaternion.Euler(0, 0, rotationOffset)); //Setup waypoints MoveBetweenPoints moveBetweenPoints = currentFish.GetComponent <MoveBetweenPoints>(); if (moveBetweenPoints != null) { moveBetweenPoints.targetA = targetA; moveBetweenPoints.targetB = targetB; } }
private void StartMovement() { if (enemySO.movementPattern.Equals(0)) { movementPoints.Insert(0, transform.position); MoveBetweenPoints movement = new MoveBetweenPoints(gameObject, movementPoints, enemySO.speed); StartCoroutine(movement.StartMoving()); } else if (enemySO.movementPattern.Equals(1)) { MoveToObject movement = new MoveToObject(gameObject, GameObject.FindWithTag("Player"), enemySO.speed); StartCoroutine(movement.StartMoving()); } else if (enemySO.movementPattern.Equals(99)) { //99 code is to not move } }
// Start is called before the first frame update void Start() { moveBetweenPoints = GetComponent <MoveBetweenPoints>(); stunned = false; }
// Update is called once per frame void Update() { delayTime -= Time.deltaTime; if (delayTime <= 0) { busy = false; } if (busy) { return; } ActionContext.canGrabBody = targets.Count > 0; //check if the player tries to grab a body if (Input.GetButtonUp("Action")) { if (!dragging) //if we aren't currently dragging a body //grab the nearest body in the list of targets { float minDist = Mathf.Infinity; GameObject nearest = null; //loop through all grabbable targets and select the closest foreach (GameObject obj in targets) { float dist = (transform.position - obj.transform.position).sqrMagnitude; if (dist < minDist) { minDist = dist; nearest = obj; } } draggedBody = nearest; if (draggedBody != null) //if we grabbed someone { if (draggedBody.CompareTag("Human")) { audioSrc.PlayOneShot(grab); } busy = true; delayTime = waitTime; //ignor collision and destroy their colliders draggedBody.GetComponent <Rigidbody2D>().collisionDetectionMode = CollisionDetectionMode2D.None; foreach (Collider2D c in draggedBody.GetComponents <Collider2D>()) { Destroy(c); } BoxCollider2D box = draggedBody.AddComponent <BoxCollider2D>(); box.isTrigger = true; //disable their behavior script draggedBody.GetComponent <Behavior>().enabled = false; //tag them as a body draggedBody.tag = "Body"; //remove any movement scripts MoveBetweenPoints script = draggedBody.GetComponent <MoveBetweenPoints>(); if (script != null) { Destroy(script); } Vision v = draggedBody.GetComponent <Vision>(); if (v != null) { v.kill(); } //set body to ignore raycasts draggedBody.layer = LayerMask.NameToLayer("Ignore Raycast"); } } else if (draggedBody != null) //drop the body { audioSrc.PlayOneShot(drop); draggedBody.layer = 0; if (van.kill(draggedBody)) //try to drop them in the van { targets.Remove(draggedBody); //remove them from the list of things that can be grabbed Destroy(draggedBody); } else //if not, drop them on the floor { draggedBody.GetComponent <Rigidbody2D>().collisionDetectionMode = CollisionDetectionMode2D.Continuous; } draggedBody = null; } } dragging = draggedBody != null; //check if we're carrying anything ActionContext.carryingBody = dragging; //set velocity direction from input velocity.Set(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"), 0); velocity.Normalize(); //normalize speed to a unit vector if (dragging) { velocity = velocity * 0.33f; //slow down the player if they're carrying a body } //calculate the vector from the player's position to the mouse Vector3 direction = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position; rotation = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg; //find the angle of the direction vector anim.SetBool("Walking", velocity.sqrMagnitude > 0); anim.SetBool("Grabbing", dragging); }
void Start() { audio = GetComponent <AudioSource>(); anim = GetComponent <Animator>(); movement = GetComponent <MoveBetweenPoints>(); }